Assembly Syntax
[label] MNEMONIC [OPERANDS] [;comment]
Assembly Syntax
[label] MNEMONIC [OPERANDS] [;comment]
Does something...
Assembly Syntax
[label] MNEMONIC [OPERANDS] [;comment]
Does something... with the operand[s]
Assembly Syntax
[label] MNEMONIC [OPERANDS] [;comment]
MOV A, 100H
Eg.
Assembly Syntax
[label] MNEMONIC [OPERANDS] [;comment]
MOV A, 100H
Eg.
Move 100H into A
Assembly Syntax
[label] MNEMONIC [OPERANDS] [;comment]
MOV A, 100H
Eg.
Move 100H into A
“bites Tom dog”
Assembly Syntax
[label] MNEMONIC [OPERANDS] [;comment]
MOV A, 100H
Eg.
dest, source
Assembly Syntax
MNEMONIC [OPERANDS] [;comment]
Assembly Syntax
MNEMONIC [OPERANDS] [;comment]
MOV A, 100H ; load 100H into A
Eg.
Assembly Syntax
[label] MNEMONIC [OPERANDS] [;comment]
MOV A, 100H ; load 100H into A
cool
Address at which
code is stored
[label] MNEMONIC [OPERANDS] [;comment]
; Simple example
; Writes Hello World to the output
JMP start
hello: DB "Hello World!" ; Variable
DB 0 ; String terminator
start:
MOV C, hello ; Point to var
MOV D, 232 ; Point to output
CALL print
HLT ; Stop execution
print: ; print(C:*from, D:*to)
PUSH A
PUSH B
MOV B, 0
.loop:
MOV A, [C] ; Get char from var
MOV [D], A ; Write to output
INC C
INC D
CMP B, [C] ; Check if end
JNZ .loop ; jump if not
POP B
POP A
RET
Assembler
directives
Assembly Simulator
https://schweigi.github.io/assembler-simulator/
x86 Mnemonics
MOV b,a move a b ; a unchanged
ADD b,a add a+b b; a unchanged
SUB b,a subtract a-b b; a unchanged
AND b,a and a AND b b bitwise; a unchanged
OR b,a or a OR b b bitwise; a unchanged
CMP b,a compare set flags as if b-a; a,b unchanged
INC rm increment rm + 1 rm
DEC rm decrement rm - 1 rm
NOT rm not 1’s complement of rm rm
NEG rm negate negative (2’s complement) of rm rm
b,a: any of m,r r,m r,r m,imm r,imm
rm: register or memory, via various addressing modes
The Art of Electronics p.994
Mnemonic Operand(s) English What it does:
x86 Mnemonics
Immediate: A value. eg. 200, 0xA4, 101b
Register: Built-in registers within the microchip.
Memory: Random Access Memory (RAM) space.
https://www.tutorialspoint.com/assembly_programming/assembly_registers.htm
General-Purpose Registers
AX
DX
CX
BX
BP
SI
DI
SP
0
15
The Art of Electronics p.994
LSB
MSB
General-Purpose Registers
AX
DX
CX
BX
BP
SI
DI
SP
0
15
Stack pointer
Destination index
Source index
Base pointer
Loop, shift, count
MUL/DIV/I/0
MUL/DIV/I/0
The Art of Electronics p.994
LSB
MSB
Base register
General-Purpose Registers
AX
DX
CX
BX
BP
SI
DI
SP
0
15
Stack pointer
Destination index
Source index
Base pointer
Loop, shift, count
MUL/DIV/I/0
MUL/DIV/I/0
The Art of Electronics p.994
LSB
MSB
Base register
Addressing Modes
DIRECT: MOV A, 100H; moves value of 100H into register A
Memory Addressing Modes
The Art of Electronics p.994
MOV B, 10; put “address” 10 in B
Memory Addressing Modes
The Art of Electronics p.994
INDIRECT:
MOV B, 10; put “address” 10 in B
MOV [B], 28; store 28 at “address” 10
Memory Addressing Modes
A vs. [A]
Register A Contents of
Register A
A 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1
BX,BP,SI,DI
Memory Addressing Modes
The Art of Electronics p.994
.data
my_var DW 0abcdh ; my_var = 0xabcd
.code
MOV A, [my_var] ; copy my_var content into A (ax=0xabcd)
Memory Addressing Modes
The Art of Electronics p.994
byte_table DB 12, 15, 16, 22 ; table of bytes
MOV A, [byte_table + 2]
INDEXED:
x86 Stack
PUSH rm push push rm onto stack (2 bytes)
POP rm pop pop 2 bytes from stack to rm
The Art of Electronics p.994
Stack
Wikipedia
x86 Control
JMP label jump jump to instr label
Jcc label jump cond jump to instr label if cc true
CALL label call push next adr, jump to instr label
RET return pop stack, jump to that adr
IRET return fr int pop stack, restore flags, return
STI set int enable interrupts
CLI clear int enable interrupts
label: via various addressing modes
cc: any of Z NZ G GE LE L C NC S NS
The Art of Electronics p.994
The Art of Electronics p.994
The Art of Electronics p.994
x86 Input/Output
IN AX, port input port AX(or AL)
OUT port, AX output AX(or AL) port
port: byte(via imm) or word (via DX)
The Art of Electronics p.994

Assembly class