Download presentation
Presentation is loading. Please wait.
Published byLucas Bryan Modified over 8 years ago
1
Overview of Assembly Language Chapter 4 S. Dandamudi
2
2005 To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005. S. Dandamudi Chapter 4: Page 2 Outline Assembly language statements Data allocation Where are the operands? Addressing modes »Register »Immediate »Direct »Indirect Data transfer instructions mov, xchg, and xlat Ambiguous moves Overview of assembly language instructions Arithmetic Conditional Iteration Logical Shift/Rotate Defining constants EQU, %assign, %define Macros Illustrative examples Performance: When to use the xlat instruction
3
2005 To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005. S. Dandamudi Chapter 4: Page 3 Data Transfer Instructions (cont’d) Ambiguous moves: PTR directive For the following data definitions.DATA table1 TIMES 20 DW 0 status TIMES 7 DB 1 the last two mov instructions are ambiguous mov EBX, table1 mov ESI, status mov [EBX],100 mov [ESI],100 Not clear whether the assembler should use byte or word equivalent of 100
4
2005 To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005. S. Dandamudi Chapter 4: Page 4 Data Transfer Instructions (cont’d) Ambiguous moves: PTR directive A type specifier can be used to clarify The last two mov instructions can be written as mov WORD [EBX],100 mov BYTE [ESI],100 WORD and BYTE are called type specifiers We can also write these statements as mov [EBX], WORD 100 mov [ESI], BYTE 100
5
2005 To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005. S. Dandamudi Chapter 4: Page 5 Data Transfer Instructions (cont’d) Ambiguous moves: PTR directive We can use the following type specifiers: Type specifierBytes addressed BYTE1 WORD 2 DWORD4 QWORD 8 TWORD10
6
2005 To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005. S. Dandamudi Chapter 4: Page 6 Data Transfer Instructions (cont’d) The xchg instruction The syntax is xchg operand1,operand2 Exchanges the values of operand1 and operand2 Examples xchg EAX,EDX xchg [response],CL xchg [total],DX Without the xchg instruction, we need a temporary register to exchange values using only the mov instruction
7
2005 To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005. S. Dandamudi Chapter 4: Page 7 Data Transfer Instructions (cont’d) The xchg instruction The xchg instruction is useful for conversion of 16-bit data between little endian and big endian forms Example: xchg AL,AH converts the data in AX into the other endian form Pentium provides bswap instruction to do similar conversion on 32-bit data bswap 32-bit register bswap works only on data located in a 32-bit register
8
2005 To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005. S. Dandamudi Chapter 4: Page 8 Data Transfer Instructions (cont’d) Example Assembly program to exchange values between AL and BL..586 option segment:use16.model small.dosseg.code start: mov al,5 ; al = 5 mov bl,3 ; bl = 3 xchg al,bl ; exchange values between al and bl
9
2005 To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005. S. Dandamudi Chapter 4: Page 9 Data Transfer Instructions (cont’d) Example mov dl,al add dl,30h mov ah,2h ;print value of al int 21h mov dl,0ah ; Line feed to print new line mov ah,2h int 21h mov dl,0dh ; carriage return character to print new line int 21h mov dl,bl ; print value of bl add dl,30h
10
2005 To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005. S. Dandamudi Chapter 4: Page 10 Data Transfer Instructions (cont’d) Example mov ah,2h int 21h mov ah,4ch ; exit int 21h end start
11
2005 To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005. S. Dandamudi Chapter 4: Page 11 Data Transfer Instructions (cont’d) The xlat instruction The xlat instruction translates bytes The format is xlatb To use xlat instruction »BX should be loaded with the starting address of the translation table »AL must contain an index in to the table –Index value starts at zero »The instruction reads the byte at this index in the translation table and stores this value in AL –The index value in AL is lost »Translation table can have at most 256 entries (due to AL)
12
2005 To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005. S. Dandamudi Chapter 4: Page 12 Data Transfer Instructions (cont’d) The xlat instruction Example: Encrypting digits Input digits: 0 1 2 3 4 5 6 7 8 9 Encrypted digits: 4 6 9 5 0 3 1 8 7 2 The program:.586 option segment:use16.model small Dosseg.data table db '4695031872'.code.startup lea bx,table
13
2005 To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005. S. Dandamudi Chapter 4: Page 13 Data Transfer Instructions (cont’d) The xlat instruction mov ah,1h ;input character int 21h sub al,'0' ; converts input character to index xlatb ; AL = encrypted digit character mov dl,al mov ah,2h ;print character located in table with input index int 21h mov ah,4ch int 21h end
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.