

nasm -fmacho64 triangle.asm & gcc hola.o &.

This is an OSX console program that writes a little triangle of asterisks to standard bss (you'll get an error if you try to use them in To reserve space (without initializing), you can use the following pseudo instructions. There are other forms check the NASM docs. To place data in memory:ĭb 0x55,0x56,0x57 three bytes in successionĭb 'hello',13,10,'$' so are string constantsĭq 0x123456789abcdef0 eight byte constantĭt 1.234567e20 extended-precision float These examples come from Chapter 3 of the docs. Most of the basic instructions have onlyĪdd reg, reg add reg, mem add reg, imm add mem, reg add mem, imm Defining Data and Reserving Space In fact, we’ll not see any such instruction in this tutorial. Instructions with two memory operands are extremely rare Here are some examples from the official docs.Ġ200 still decimal - the leading 0 does not make it octalĠc8h hex - h suffix, but leading 0 is required because c8h looks like a varĠhc8 hex - for some reason NASM likes 0hĠb1100_1000 binary - 0b prefix, and by the way, underscores are allowed uses the address of the variable 'counter' as the displacement The base the register with the scale is called the index. The number is called the displacement the plain register is called R3 are named:Īnd finally, there are 16 XMM registers, each 128 bits wide, named: R0B R1B R2B R3B R4B R5B R6B R7B R8B R9B R10B R11B R12B R13B R14B R15Bįor historical reasons, bits 15 through 8 of R0. You can treat the lowest 8-bits of each register as a register itself but using these names: You can treat the lowest 16-bits of each register as a register itself but using these names: (Note that 8 of the registers have alternate names.) You can treat the lowestģ2-bits of each register as a register itself but using these names:
HOW TO WRITE COMPUTER CODE VIDEO TUTORIAL 64 BITS
The 16 integer registers are 64 bits wide and are called: You should already know what the registers are, but here is a quick In this tutorial we only care about the integer registers and the xmm The Three Kinds of Operands Register Operands That declares bytes that will be in memory when the program runs Syscall Invoke an operating system routine Mov x, y x ← y and x, y x ← x and y or x, y x ← x or y xor x, y x ← x xor y add x, y x ← x + y sub x, y x ← x – y inc x x ← x + 1
HOW TO WRITE COMPUTER CODE VIDEO TUTORIAL MANUALS
The Intel Processor Manuals Your First Few Instructions.NASM is an awesome assembler, but assembly language is complex. text and your constant data in a section called. Generally, you put code in a section called.

Most lines have an instruction followed by zero or more operands. Most programs consist of directives followed by one or more sections. Exercise: Identify the differences between the two programs.
