0
Assembly Language Fundamentals of Assembly language Motaz K. Saad Spring 2007 Motaz K. Saad, Dept. of CS
Review of existing concepts <ul><li>Comments </li></ul><ul><li>Directives (page, segment, title) </li></ul><ul><li>Data ty...
Operand Types <ul><li>Three basic types of operands: </li></ul><ul><ul><li>Immediate – a constant integer (8, 16, or 32 bi...
Data transfer instructions <ul><li>MOV instruction </li></ul><ul><ul><li>Move from source to destination. Syntax: </li></u...
MOV Instruction .data count DB 100 wVal  DW 2 .code mov bl,count mov ax,wVal mov count,al mov al,wVal ; error mov ax,count...
<ul><li>Load Effective Address.  REG = address of memory (offset)  </li></ul><ul><li>LEA register/memory </li></ul><ul><li...
Arithmetic instructions <ul><li>INC and DEC instruction </li></ul><ul><ul><li>Increasing or decreasing the contents of reg...
Arithmetic instructions <ul><li>ADD </li></ul><ul><ul><li>ADD/SUB operand1, operand 2 </li></ul></ul><ul><ul><li>operand1 ...
Arithmetic instructions <ul><li>SUB </li></ul><ul><ul><li>SUB operand1, operand 2 </li></ul></ul><ul><ul><li>operand1 =ope...
Arithmetic instructions <ul><li>MUL operand </li></ul><ul><ul><li>Unsigned multiply.  Operand: register/memory </li></ul><...
Arithmetic instructions <ul><li>IMUL operand </li></ul><ul><ul><li>Signed multiply.  Operand: register/memory </li></ul></...
Arithmetic instructions <ul><li>DIV operand </li></ul><ul><ul><li>Unsigned multiply.  Operand: register/memory </li></ul><...
Arithmetic instructions <ul><li>IDIV operand </li></ul><ul><ul><li>Signed multiply.  Operand: register/memory </li></ul></...
<ul><ul><li>Write a program to convert from  Celsius to Fahrenheit  and vice versa : </li></ul></ul><ul><ul><li>Tc = (5/9)...
Repetitive move instructions copying a string to another TITLE A04ASM1 (EXE)  Move and add operations ; ------------------...
Repetitive move instructions <ul><li>.CODE </li></ul><ul><li>MAIN PROC  FAR </li></ul><ul><li>MOV AX, @DATA </li></ul><ul>...
Repetitive move instructions <ul><li>DEC CX </li></ul><ul><ul><li>ZF = 1 if CX = 0 </li></ul></ul><ul><li>JNZ LABEL </li><...
Practice <ul><li>Develop an assembly program to: </li></ul><ul><ul><li>Define byte items: BYTE1 and BYTE2 (Assign any valu...
Addressing mode <ul><li>Register addressing:  </li></ul><ul><ul><li>E.g ADD AX, BX </li></ul></ul><ul><li>fastest type of ...
Addressing mode <ul><li>Direct-Offset addressing </li></ul><ul><li>use arithmetic instruction to modify an address </li></...
Addressing mode <ul><li>Base Displacement Addressing </li></ul><ul><li>Uses BX, BP and DI, SI and combine with a displacem...
Addressing mode <ul><li>Base-Index Displacement Addressing </li></ul><ul><li>Combine BX, BP and DI, SI and a displacement ...
Upcoming SlideShare
Loading in...5
×

Assembly Language Lecture 4

14,859

Published on

Assembly Language Lecture 4

Published in: Technology, Education
2 Comments
9 Likes
Statistics
Notes
  • this is a great site 4 all students
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • I really appreciate these powerpoints you made. My professor makes no sense, speaks and writes really fast which is hard for me to follow. You make all the questions I've had answered very clearly!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
14,859
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
1,135
Comments
2
Likes
9
Embeds 0
No embeds

No notes for slide

Transcript of "Assembly Language Lecture 4"

  1. 1. Assembly Language Fundamentals of Assembly language Motaz K. Saad Spring 2007 Motaz K. Saad, Dept. of CS
  2. 2. Review of existing concepts <ul><li>Comments </li></ul><ul><li>Directives (page, segment, title) </li></ul><ul><li>Data type (Byte (DB), Word(DW), Doubleword(DD), String </li></ul><ul><li>Some arithmetic operations: ADD,SUB,MUL,DIV </li></ul>Motaz K. Saad, Dept. of CS
  3. 3. Operand Types <ul><li>Three basic types of operands: </li></ul><ul><ul><li>Immediate – a constant integer (8, 16, or 32 bits) </li></ul></ul><ul><ul><ul><li>value is encoded within the instruction </li></ul></ul></ul><ul><ul><li>Register – the name of a register </li></ul></ul><ul><ul><ul><li>register name is converted to a number and encoded within the instruction </li></ul></ul></ul><ul><ul><li>Memory – reference to a location in memory </li></ul></ul><ul><ul><ul><li>memory address is encoded within the instruction, or a register holds the address of a memory location </li></ul></ul></ul>Motaz K. Saad, Dept. of CS
  4. 4. Data transfer instructions <ul><li>MOV instruction </li></ul><ul><ul><li>Move from source to destination. Syntax: </li></ul></ul><ul><ul><ul><li>MOV destination,source </li></ul></ul></ul><ul><ul><li>Transfers data referenced by the address of the second operand to the address of the first operand </li></ul></ul><ul><ul><li>Destination has to have the same length as source </li></ul></ul><ul><ul><li>[label:] MOV register/memory register/memory/immediate </li></ul></ul><ul><ul><li>Example: </li></ul></ul><ul><ul><li>MOV F, AX ; // Move content of AX to the variable F </li></ul></ul><ul><ul><li>MOV CX, D ;// Move value of D to CX </li></ul></ul><ul><ul><li>MOV ES, AX </li></ul></ul><ul><ul><li>MOV AX, 215 </li></ul></ul>Motaz K. Saad, Dept. of CS
  5. 5. MOV Instruction .data count DB 100 wVal DW 2 .code mov bl,count mov ax,wVal mov count,al mov al,wVal ; error mov ax,count ; error mov eax,count ; error <ul><li>Move from source to destination. Syntax: </li></ul><ul><ul><ul><li>MOV destination,source </li></ul></ul></ul><ul><li>No more than one memory operand permitted </li></ul><ul><ul><li>MOV VAR1,VAR2 </li></ul></ul><ul><li>CS, IP, and IP cannot be the destination </li></ul><ul><ul><li>MOV IP, 100 </li></ul></ul><ul><li>No immediate to segment moves </li></ul><ul><ul><li>MOV DS, @DATA </li></ul></ul>Motaz K. Saad, Dept. of CS
  6. 6. <ul><li>Load Effective Address. REG = address of memory (offset) </li></ul><ul><li>LEA register/memory </li></ul><ul><li>Example: </li></ul><ul><li>LEA AX, m ;load offset address of m to AX </li></ul>LEA instruction Motaz K. Saad, Dept. of CS
  7. 7. Arithmetic instructions <ul><li>INC and DEC instruction </li></ul><ul><ul><li>Increasing or decreasing the contents of register or memory location by 1 </li></ul></ul><ul><ul><li>INC/DEC register/memory </li></ul></ul><ul><ul><li>Flag: OF, SF and ZF </li></ul></ul><ul><ul><li>OF:is set when an instruction resulted in a carry into the sign bit of the result. </li></ul></ul><ul><ul><li>SF: is set if the sign bit of a result is set </li></ul></ul><ul><ul><li>ZF: is set if the result is equal to 0. </li></ul></ul>Motaz K. Saad, Dept. of CS
  8. 8. Arithmetic instructions <ul><li>ADD </li></ul><ul><ul><li>ADD/SUB operand1, operand 2 </li></ul></ul><ul><ul><li>operand1 =operand 1 + operand 2 </li></ul></ul><ul><ul><li>Operand 1: register/memory </li></ul></ul><ul><ul><li>Operand 2: register/memory/immediate </li></ul></ul>Motaz K. Saad, Dept. of CS
  9. 9. Arithmetic instructions <ul><li>SUB </li></ul><ul><ul><li>SUB operand1, operand 2 </li></ul></ul><ul><ul><li>operand1 =operand 1 - operand 2 </li></ul></ul><ul><ul><li>operand 1: register/memory </li></ul></ul><ul><ul><li>operand 2: register/memory/immediate </li></ul></ul>Motaz K. Saad, Dept. of CS
  10. 10. Arithmetic instructions <ul><li>MUL operand </li></ul><ul><ul><li>Unsigned multiply. Operand: register/memory </li></ul></ul>Motaz K. Saad, Dept. of CS
  11. 11. Arithmetic instructions <ul><li>IMUL operand </li></ul><ul><ul><li>Signed multiply. Operand: register/memory </li></ul></ul><ul><ul><li>Example: </li></ul></ul><ul><ul><li>MOV AX, -2 </li></ul></ul><ul><ul><li>MOV CX, -3 </li></ul></ul><ul><ul><li>IMUL CX ; AX = +6 </li></ul></ul><ul><ul><li>CF = 0 </li></ul></ul>Motaz K. Saad, Dept. of CS
  12. 12. Arithmetic instructions <ul><li>DIV operand </li></ul><ul><ul><li>Unsigned multiply. Operand: register/memory </li></ul></ul><ul><ul><li>when operand is a byte : AL = AX / operand AH = remainder (modulus) </li></ul></ul><ul><ul><li>when operand is a word : DX = remainder (modulus) </li></ul></ul>Motaz K. Saad, Dept. of CS
  13. 13. Arithmetic instructions <ul><li>IDIV operand </li></ul><ul><ul><li>Signed multiply. Operand: register/memory </li></ul></ul><ul><ul><li>when operand is a byte : AL = AX / operand AH = remainder (modulus) </li></ul></ul><ul><ul><li>when operand is a word : DX = remainder (modulus) </li></ul></ul>Motaz K. Saad, Dept. of CS
  14. 14. <ul><ul><li>Write a program to convert from Celsius to Fahrenheit and vice versa : </li></ul></ul><ul><ul><li>Tc = (5/9)*(Tf-32) </li></ul></ul><ul><li>Tc: censius </li></ul><ul><li>Tf: fahrenheit </li></ul><ul><li>( The result may not be accurate due to the integer division but that is fine) </li></ul>Practice Motaz K. Saad, Dept. of CS
  15. 15. Repetitive move instructions copying a string to another TITLE A04ASM1 (EXE) Move and add operations ; --------------------------------------------- .STACK ; ---------------------------------------------- .DATA STRING1 DB &quot;12345678&quot;,&quot;$&quot; STRING2 DB ? Motaz K. Saad, Dept. of CS
  16. 16. Repetitive move instructions <ul><li>.CODE </li></ul><ul><li>MAIN PROC FAR </li></ul><ul><li>MOV AX, @DATA </li></ul><ul><li>MOV DS, AX </li></ul><ul><li>MOV ES, AX </li></ul><ul><li>MOV CX, 09 ; Initialize to move 9 characters </li></ul><ul><li>LEA SI, STRING1 ; Initialize source index register to offset of string 1 </li></ul><ul><li>LEA DI, STRING2 ; Initialize destination index register to offset of string 2 </li></ul><ul><li>BEGINLOOP: </li></ul><ul><li>MOV AL,[SI] ; Get a current character from string 1 to AL </li></ul><ul><li>MOV [DI], AL ; Move it to the current character in string 2 </li></ul><ul><li>INC SI ; Move to the next character in string 1 </li></ul><ul><li>INC DI ; Move to the next character in string 2 </li></ul><ul><li>DEC CX ; Decrease the count for loop </li></ul><ul><li>JNZ BEGINLOOP ; Continue to loop if count is not 0 </li></ul><ul><li>MOV AH, 09H </li></ul><ul><li>LEA DX, STRING2 </li></ul><ul><li>int 21H ; Display String 2 </li></ul><ul><li>.EXIT </li></ul><ul><li>MAIN ENDP ;End of procedure </li></ul><ul><li>END MAIN ;End of program </li></ul>Motaz K. Saad, Dept. of CS
  17. 17. Repetitive move instructions <ul><li>DEC CX </li></ul><ul><ul><li>ZF = 1 if CX = 0 </li></ul></ul><ul><li>JNZ LABEL </li></ul><ul><li>if ZF = 0 then jump to the label </li></ul>Motaz K. Saad, Dept. of CS
  18. 18. Practice <ul><li>Develop an assembly program to: </li></ul><ul><ul><li>Define byte items: BYTE1 and BYTE2 (Assign any values for these two variables) </li></ul></ul><ul><ul><li>Define a word item: WORD3 and WORD3=0 </li></ul></ul><ul><ul><li>Move content of Byte1 to AL </li></ul></ul><ul><ul><li>Add content of Byte2 to AL </li></ul></ul><ul><ul><li>Set DL= 42H </li></ul></ul><ul><ul><li>Exchange the content of AL and DL </li></ul></ul><ul><ul><li>Multiply the contents of AL by DL </li></ul></ul><ul><ul><li>Transfer product from AX to WORD3 </li></ul></ul>Motaz K. Saad, Dept. of CS
  19. 19. Addressing mode <ul><li>Register addressing: </li></ul><ul><ul><li>E.g ADD AX, BX </li></ul></ul><ul><li>fastest type of operations </li></ul><ul><li>Immediate addressing </li></ul><ul><ul><li>Immediate contains a constant value or an expression </li></ul></ul><ul><ul><li>E.g: MOV AX, 0245H </li></ul></ul><ul><li>Direct memory addressing </li></ul><ul><ul><li>One of operand references a memory location and the other operand references a register </li></ul></ul><ul><ul><li>E.G MOV FLDF, AX </li></ul></ul>Motaz K. Saad, Dept. of CS
  20. 20. Addressing mode <ul><li>Direct-Offset addressing </li></ul><ul><li>use arithmetic instruction to modify an address </li></ul><ul><li>e.g MOV CX, DATAZ+2 </li></ul><ul><li>Indirect memory addressing </li></ul><ul><li>Use BX and BP, DI and SI within [ ] </li></ul><ul><li>e.g. MOV [BX], CL </li></ul>Motaz K. Saad, Dept. of CS
  21. 21. Addressing mode <ul><li>Base Displacement Addressing </li></ul><ul><li>Uses BX, BP and DI, SI and combine with a displacement to form an effective address </li></ul><ul><li>E.g MOV AL,[SI+2] </li></ul><ul><li>Base-Index Addressing </li></ul><ul><li>Combine BX,BP with DI,SI to form effective address </li></ul><ul><li>E.G MOV AL,[BX+SI] </li></ul>Motaz K. Saad, Dept. of CS
  22. 22. Addressing mode <ul><li>Base-Index Displacement Addressing </li></ul><ul><li>Combine BX, BP and DI, SI and a displacement to form an effective address </li></ul><ul><li>E.g MOV AL,[BX+SI+2] </li></ul>Motaz K. Saad, Dept. of CS
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×