Assembly Language Lab #4

[Pages:11]Islamic University of Gaza Computer Engineering Department

2009

Assembly Language Lab #4

Eng. Tahani Z. Fourah

Islamic University of Gaza

Assembly Language Lab #4

Boolean Instructions and Conditional Structured

1. NOT Instruction: Performs a bitwise Boolean NOT operation on a single destination operand ? Syntax: (no flag affected) NOT destination ? Example: mov al, 11110000b not al

2. AND Instruction: Performs a bitwise Boolean AND operation between each pair of matching bits in two operands ? Syntax: (O=0,C=0,SZP)

AND destination, source ? Example:

mov al, 00111011b and al, 00001111b

3. OR Instruction : Performs a bitwise Boolean OR operation between each pair of matching bits in two operands ? Syntax: (O=0,C=0,SZP) OR destination, source ? Example: mov dl, 00111011b or dl, 00001111b

23

Assembly Language Lab #4

4. XOR Instruction : Performs a bitwise Boolean exclusive-OR operation between each pair of matching bits in two operands ? Syntax: (O=0,C=0,SZP) XOR destination, source ? Example: mov dl, 00111011b xor dl, 00001111b

5. Test Instruction : Performs a nondestructive AND operation between each pair of matching bits in two operands. ? No operands are modified, but the flags are affected. ? Example: jump to a label if either bit 0 or bit 1 in AL is set. test al,00000011b jnz ValueFound ? Example: jump to a label if neither bit 0 nor bit 1 in AL is set. test al,00000011b jz ValueNotFound

24

Assembly Language Lab #4 Applications:

Conditional structures:

Assembly language programmers can easily translate logical statements written in C++/Java into assembly language. For example:

25

Assembly Language Lab #4

Implement the following pseudocode in assembly language. All values are 32bit signed integers:

Compound expression with AND:

Compound Expression with OR:

26

Assembly Language Lab #4

Lab Work:

1. Write an assembly language program that allow user to input one digit number and determine if it is even or odd

Dosseg .model small .data msg1 db 'Enter a number: ','$' msg2 db 'the number is odd','$' msg3 db 'the number is even','$' .code main: mov ax,@data mov ds,ax mov ah,9 mov dx,offset msg1 int 21h mov ah,1 int 21h and al,01 cmp al,0 je EvenNum mov ah,2 mov dl,0AH int 21h mov dl,0DH int 21h mov ah,9 mov dx,offset msg2 int 21h jmp exit EvenNum: mov ah,2 mov dl,0AH int 21h mov dl,0DH int 21h mov ah,9 mov dx,offset msg3 int 21h exit: mov ah,4ch int 21h end main

27

Assembly Language Lab #4

Another version of the program

Dosseg .model small .data msg1 db 'Enter a number: ','$' msg2 db 'the number is odd','$' msg3 db 'the number is even','$' .code main: mov ax,@data mov ds,ax mov ah,9 mov dx,offset msg1 int 21h mov ah,1 int 21h L: cmp al,0 je EvenNum cmp al,1 je OddNum sub al,2 jmp L OddNum: mov ah,2 mov dl,0AH int 21h mov dl,0DH int 21h mov ah,9 mov dx,offset msg2 int 21h jmp exit EvenNum: mov ah,2 mov dl,0AH int 21h mov dl,0DH int 21h mov ah,9 mov dx,offset msg3 int 21h exit: mov ah,4ch int 21h end main

28

Assembly Language Lab #4

2. Write an assembly language program that determine number of ones in a byte( assume that # ones are stored in bl )

Dosseg .model small .code main: mov cx,8 mov al,0A4H X: rol al,1 jc L loop X jmp exit L: add bl,1 loop X exit: mov ah,4ch int 21h end main

29

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download