210 likes | 354 Views
Computer Organization & Assembly Language. University of Sargodha, Lahore Campus Prepared by Ali Saeed. .DATA directive. DB-define byte DW-define word DD-define double word (two consecutive words) DQ- define quadword (four consecutive words) DT-define ten consecutive bytes.
E N D
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed
.DATA directive • DB-define byte • DW-define word • DD-define double word (two consecutive words) • DQ- define quadword(four consecutive words) • DT-define ten consecutive bytes
Declaration of Assembly Language • Name Type initial_value • Var DB 64 ;Declare a byte, referred to as location var, containing the value 64. • Var2 DB ? ;Declare an uninitialized byte, referred to as location var2. • DB 10 ;Declare a byte with no label, containing the value 10. Its location is var2 + 1. • X DW ? ; Declare a 2-byte uninitialized value, referred to as location X. • Y DD 30000; Declare a 4-byte value, referred to as location Y, initialized to 30000.
Illegal Variable Names • Two Words Contains a blank • 2abc Begins with a digit • A45.45 . Is not allowed • You&mecontain an illegal character
Types of Instructions • On the bases of operands instructions can be divided into three types • No operands e.g NOP • One operands e.g INC AX • Two operands e.g ADD Word1,2 • In two operands instructions first operand is as destination where result is stored • Second operand is source operand source is not usually modified after completion of instruction
Comments in Assembly • Programmer use comments to say something about code • ; symbol is use to define comment • This symbol is use at the start of each statement on which we want to apply comments. • Assembler will ignore the statements typed after ; • MOV CX,0 ;mov 0 in CX register
Program data (Numbers) • Processor can only operate on binary numbers but Assembler can accept Binary, Decimal and Hex numbers • B or b is use at the end to define binary • D or d is use at the end to define decimal • H or h is use at the end to define Hex • Hex number must begin with decimal and end with H
Program data (Numbers) • Examples • 1110101 Decimal • 1010101B Binary • 7672321 Decimal • -22321D Decimal • 1,2212 Illegal • 173BH Hexadecimal • FFFFH Illegal • 0FFFFH Hexadecimal
Instructions • <reg32> Any 32-bit register (EAX, EBX, ECX, EDX, ESI, EDI, ESP, or EBP) • < reg16> Any 16-bit register (AX, BX, CX, or DX) • < reg8> Any 8-bit register (AH, BH, CH, DH, AL, BL, CL, or DL) • < reg> Any register • < mem> A memory address (e.g., [eax], [var + 4], or dwordptr [eax+ebx]) • < con32> Any 32-bit constant • < con16> Any 16-bit constant • < con8> Any 8-bit constant • < con> Any 8-, 16-, or 32-bit constant
Data Movement Instructions • The mov instruction copies the data item referred to by its second operand (i.e. register contents, memory contents, or a constant value) into the location referred to by its first operand
Data Movement Instructions • Syntaxmov <reg>,<reg>mov <reg>,<mem>mov <mem>,<reg>mov <reg>,<const>mov <mem>,<const> • Examplesmoveax, ebx — copy the value in ebx into eaxmov byte ptr [var], 5 — store the value 5 into the byte at location var
Size Directives • Size of both operand of mov instruction must be same • But, in some cases these may be imbegious like, mov [ebx], 2.
Size Directives • mov BYTE PTR [ebx], 2; Move 2 into the single byte at the address stored in EBX. • mov WORD PTR [ebx], 2; Move the 16-bit integer representation of 2 into the 2 bytes starting at the address in EBX. • mov DWORD PTR [ebx], 2 ; Move the 32-bit integer representation of 2 into the 4 bytes starting at the address in EBX.
XCHG instruction • XCHG, exchange is use to exchange the content of two operands • XCHG Destination, Source
Add Instruction • The sub instruction stores in the value of its first operand the result of subtracting the value of its second operand from the value of its first operand • Syntaxadd <reg>,<reg>add <reg>,<mem>add <mem>,<reg>add <reg>,<con>add <mem>,<con> • Examplesadd eax, 10 — EAX ← EAX + 10add BYTE PTR [var], 10 — add 10 to the single byte stored at memory address var
Sub Instruction • The sub instruction stores in the value of its first operand the result of subtracting the value of its second operand from the value of its first operand • Syntaxsub <reg>,<reg>sub <reg>,<mem>sub <mem>,<reg>sub <reg>,<con>sub <mem>,<con> • Examplessub al, ah — AL ← AL - AHsub eax, 216 — subtract 216 from the value stored in EAX
inc, dec — Increment, Decrement • The inc instruction increments the contents of its operand by one • The dec instruction decrements the contents of its operand by one.
inc, dec — Increment, Decrement • Syntaxinc <reg>inc <mem>dec <reg>dec <mem> • Examplesdeceax— subtract one from the contents of EAX.inc DWORD PTR [var] — add one to the 32-bit integer stored at location var