Computer Organization Assembly Language: Prof. Muhammad Saeed
Computer Organization Assembly Language: Prof. Muhammad Saeed
And
Assembly Language
III
Prof. Muhammad Saeed
1/27/2015
Language Instructions
MOV
MOVreg, reg
MOVmem, reg
MOVreg, mem
MOVmem, imm
MOVreg, imm
MOVZX
MOVZXreg32,
reg/mem8
MOVZXreg32,
reg/mem16
MOVZXreg16,
reg/mem8
MOVSXreg32,
MOVSX
1/27/2015
reg/mem8
MOVSXreg32,
reg/mem16
MOVSXreg16,
Computer Architecture & Assembly Language
reg/mem8
Language Instructions
XCHG
XCHGreg, reg
XCHGreg,
mem
XCHGmem,
reg
INC
reg/mem
DEC
reg/mem
INC, DEC
ADD, SUB
NEG
NEGreg
NEGmem
1/27/2015
Language Instructions
PUSH
PUSH
reg/mem16
PUSH
reg/mem32
PUSHimm32
POP
POPreg/mem16
POPreg/mem32
Language Instructions
PUSHFD and POPFD
The PUSHFD instruction pushes the 32-bit EFLAGS register on
the stack, and POPFD pops the stack into EFLAGS.
Language Instructions
LOOP
The LOOP instruction assumes that theECX (or CX) register
contains the loop count. When the loop instruction is executed,
the CX register is decremented and the control jumps to the
target label, until the CX register value reaches zero.
Unconditional Jump
Jmp label1
Language Instructions
Conditional Jumps
Following are the conditional jump instructions used on signed data
Instruction
Description
Flags tested
JE/JZ
ZF
JNE/JNZ
ZF
JG/JNLE
JGE/JNL
JL/JNGE
OF, SF
JLE/JNG
OF, SF, ZF
Language Instructions
Conditional Jumps
Following are the conditional jump instructions used on unsigned data
Instructio Description
n
Flags tested
JE/JZ
ZF
JNE/JNZ
ZF
JA/JNBE
CF, ZF
JAE/JNB
CF
JB/JNAE
CF
Language Instructions
Conditional Jumps
The following conditional jump instructions have special uses and check the
value of flags
Instructi Description
on
Flags
tested
JXCZ
Jump if CX is Zero
none
JC
Jump If Carry
CF
JNC
Jump If No Carry
CF
JO
Jump If Overflow
OF
JNO
Jump If No Overflow
OF
JP/JPE
PF
JNP/JPO
JS
SF
JNS
SF
Language Instructions
AND
ANDreg,reg
ANDreg,mem
ANDreg,imm
ANDmem,reg
ANDmem,imm
OR
ORreg,reg
ORreg,mem
ORreg,imm
ORmem,reg
ORmem,imm
Language Instructions
XOR
ORreg,reg
ORreg,mem
ORreg,imm
ORmem,reg
ORmem,imm
NOT
NOTreg
NOTmem
Language Instructions
TEST
The TEST instruction performs an implied AND
operation between each pair of matching bits
in two operands and sets the Sign, Zero, and
Parity flags based on the value assigned to the
destination operand. The only difference
between TEST and AND is that TEST does not
modify the destination operand.
The TEST instruction always clears the
Overflow and Carry flags. It modifies the Sign,
Zero, and Parity flags in the same way as the
AND instruction.
Language Instructions
CMP
In x86 assembly language we use the CMP
instruction to compare integers. Character
codes are also integers, so they work with CMP
as well. The CMP (compare) instruction
performs an implied subtraction of a source
operand from a destination operand. Neither
operand is modified.
CMP uses the same operand combinations as
the AND instruction.
Language Instructions
Directive
Instruction
Procedure
myproc PROC
ret
myproc endp
Macro
myMacro MACRO
..
endm
(myMacro)
(call myproc)
Language Instructions
PTR Operator
LENGTHOF Operator
SIZEOF Operator
Var1
WORD
Var2 DWORD 20
SIZEOF
var1
($ - array)
Array
BYTE
0dh, 0ah
elements in an array
20 DUP(0)
The SIZEOF operator
DUP(0) counts the number of
bytes in an array
WELCOME,
Language Instructions
LABEL Directive
.DATA
val16
LABEL
WORD
val32
DWORD
12345678h
.CODE
mov ax, val16
mov dx, [val16+2]
.DATA
LongValue LABEL
DWORD
val1 WORD
5678h
val2 WORD
1234h
.CODE
Language Instructions
Indexed Operand
.DATA
array BYTE 10h, 20h,
30h
.CODE
mov esi, 0
mov al, array[esi]
.CODE
mov esi, 3 * TYPE array
Language Instructions
Program
1st Program
.586
.MODEL flat, stdcall
option casemap :none
Include D:\msaeed\academic\assemblylanguage\masm32\include\windows.inc
Include D:\msaeed\academic\assemblylanguage\masm32\include\kernel32.inc
Include D:\msaeed\academic\assemblylanguage\masm32\include\user32.inc
Includelib D:\msaeed\academic\assemblylanguage\masm32\lib\kernel32.lib
Includelib D:\msaeed\academic\assemblylanguage\masm32\lib\user32.lib
.DATA
WindowTitle BYTE
Greetings",0
Message
BYTE
Hello, World",0
.CODE
main:
invoke MessageBox, NULL, ADDR Message, ADDR WindowTitle, MB_OK
invoke ExitProcess, eax
end main
1/27/2015
21
END