1 / 21

Computer Organization & Assembly Language

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.

treva
Télécharger la présentation

Computer Organization & Assembly Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed

  2. .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

  3. 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.

  4. Illegal Variable Names • Two Words Contains a blank • 2abc Begins with a digit • A45.45 . Is not allowed • You&mecontain an illegal character

  5. 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

  6. 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

  7. 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

  8. Program data (Numbers) • Examples • 1110101 Decimal • 1010101B Binary • 7672321 Decimal • -22321D Decimal • 1,2212 Illegal • 173BH Hexadecimal • FFFFH Illegal • 0FFFFH Hexadecimal

  9. 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

  10. 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

  11. Data Movement Instructions • Syntaxmov <reg>,<reg>mov <reg>,<mem>mov <mem>,<reg>mov <reg>,<const>mov <mem>,<const> • Examplesmoveax, ebx — copy the value of ebx into eaxmov byte ptr [var], 5 — store the value 5 into the byte at location var

  12. MOV

  13. Size Directives • Size of both operand of mov instruction must be same • But, in some cases these may be ambiguous like, mov [ebx], 2.

  14. 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.

  15. XCHG instruction • XCHG, exchange is use to exchange the content of two operands • XCHG Destination, Source

  16. Add Instruction • The add instruction stores in the value of its first operand the result of addition 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

  17. 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

  18. 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.

  19. 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

  20. ADD, SUB, INC and DEC

  21. Thanks

More Related