Assembly Language Fundamentals: Javeria Amin
Assembly Language Fundamentals: Javeria Amin
Javeria Amin
Chapter Overview
2
Integer constants
Integer expressions
Character and string constants
Reserved words and identifiers
Directives and instructions
Labels
Mnemonics and Operands
Comments
Examples
Example Program
4
main PROC
mov eax, 5 ; move 5 to the EAX register
add eax, 6 ; add 6 to the EAX register
call WriteInt ; display value in EAX
exit ; quit
main ENDP
q | o – octal
d – decimal
b – binary
r – encoded real
Basic syntax
[label:] mnemonic [operands] [ ; comment]
Labels
8
Code label
target of jump and loop instructions
Instruction Mnemonics
examples: MOV, ADD, SUB, MUL, INC, DEC
Operands
constant 96
constant expression 2+4
register eax
memory (data label) count
STC instruction
stc ; set Carry flag
INC instruction
inc eax ; add 1 to EAX
MOV instruction
mov count, ebx ; move EBX to count
; first operation is destination
; second is the source
IMUL instruction (three operands)
imul eax, ebx, 5 ; ebx multiplied by 5, product in EAX
Comments
11
Single-line comments
begin with semicolon (;)
Multi-line comments
begin with COMMENT directive and a programmer-
chosen character
end with the same programmer-chosen character
Comments
12
No operands
stc ; set Carry flag
One operand
inc eax ; register
inc myByte ; memory
Two operands
add ebx,ecx ; register, register
sub myByte,25 ; memory, constant
add eax,36 * 25 ; register, constant-
expression
What's Next
14
INCLUDE Irvine32.inc
.code
main PROC
mov eax,10000h ; EAX = 10000h
add eax,40000h ; EAX = 50000h
sub eax,20000h ; EAX = 30000h
call DumpRegs ; display registers
exit
main ENDP
END main
Example Output
16
Other suggestions
descriptive identifier names
spaces surrounding arithmetic operators
blank lines between procedures
Alternative Version of AddSub
18
.code
main PROC
mov eax,10000h ; EAX = 10000h
add eax,40000h ; EAX = 50000h
sub eax,20000h ; EAX = 30000h
call DumpRegs
INVOKE ExitProcess,0
main ENDP
END main
Program Template
19
TITLE Program Template (Template.asm)
;***************************************************
; Program Name:
; Program Description:
; Author:
; Version:
; Date:
; Other Information:
;***************************************************
INCLUDE Irvine32.inc
.data
; (insert variables here)
.code
main PROC
; (insert executable instructions here)
exit
main ENDP
; (insert additional procedures here)
END main
What's Next
20
Assemble-Link-Execute Cycle
Listing File
Map File
Assemble-Link Execute Cycle
22
Link
Library
Step 2: Step 3: Step 4:
Source assembler Object linker Executable OS loader
Output
File File File
Listing Map
Step 1: text editor File File
Assemble-Link-Execute
23
Example: addSub.lst
Map File
25
size
segment type
BYTE, SBYTE
8-bit unsigned integer; 8-bit signed integer
WORD, SWORD
16-bit unsigned & signed integer
DWORD, SDWORD
32-bit unsigned & signed integer
QWORD
64-bit integer
TBYTE
80-bit integer
Data Definition Statement
30
value1 BYTE 10
Defining BYTE and SBYTE Data
31
Example:
val1 DWORD 12345678h
Adding Variables to AddSub
41