Uploaded by nihar.ripah.edu.pk

lab 8

advertisement
Riphah International University
Computer Organization and Assembly Language
Lab Manual 8
We shall cover following programs in this manual.
•
•
•
Flag registers (0, 1)
Carry flag, parity flag, auxiliary flag, zero flag, sign flag, trap flag, interrupt flag, direction and
overflow flag
Jump conditional and unconditional and compare
Flag Registers:
Flag registers contains state of the processor. In conditional statement we shift the control to specific
line no based on the condition. To study flag registers is also important because most of CPU operations
and register operations are controlled by flag registers, e.g, int 21h we used this interrupt statement
many time before, similarly during binary addition or subtraction, comparison operations or conditional
jump flag registers play important role.
Carry Flag
Handles the last carry out bit. For example, during addition.
Parity Flag
Verifies the validity of bit. Its value is 1 in case of even no of bits, and 0 in case of odd numbers
1
Auxiliary Flag;
Handles the every third carry out bit. For example during addition. Its value is 1 in case of 3rd bit carry
exists other wise its value is 0.
Zero flag:
It handles if result is zero, for example in binary subtraction the result is zero.
Sign Flag:
It handles negative sign number. Its value is 1 in case of negative and 0 in case of positive.
Trap Flag:
This flag handles error. Its value is 1 if there is error in code and 0 in case of no error.
Interrupt Flag:
It handles interrupt, its value is 1 if interrupt is called for example int 21h.
Direction flag:
To control the direction of reading strings. For example ‘sample$’
Overflow Flag:
In case of result is too big to fit in registers this flag handles the overflow.
Jump statement :
Two types of jump statement. You can transfer program control on the base of condition or without any
condition.
Syntax of unconditional jump
JMP label
For example
.dosseg
.
.
.main proc
Mov
L1:
Mov dl,’b’
Mov ah,2
Int 21h
jmp L1
endmain
2
Syntax of conditional jump
Opcode lablel
Opcode is mnemonics used to transfer control of program.
.dosseg
.
.
.main proc
L2:
Mov ah, 1
Int 21h
Mov dl,3
je L2
mov ah, 4ch
int 21h
endmain
comparison opcodes:
JE , JZ ;;; jump if equal (checks if two umbers are equal if yes then jumps to label) jz means jump if zero
JNE, JNZ,
jump if not equal (checks if two umbers are not equal if yes then jumps to label)
JL, JB
jump if less or below (checks if one number is less if yes then jumps to label)
JLE, JBE
jump if less or equal (checks if one number is less or equal if yes then jumps to label)
JG, JA
jump if greater or above (checks if one number is greater if yes then jumps to label)
JGE, JAE
label)
jump if greater or equal (checks if one number is greater or equal if yes then jumps to
Example Program 1
;program to to compare two digits
dosseg
.model small
.stack 100h
.data
Msg1 DB ‘numbers are equal$’
Msg2 DB ‘numbers are not equal$’
.code
main proc
3
mov ax, @data
mov ds, ax
mov dl, ‘3’
mov ah, 1
int 21h
cmp al, dl
je label1
mov dx, offset msg2
mov ah,9
int 21h
mov ah,4ch
int 21h
label1:
mov dx, offset msg1
mov ah,9
int 21h
mov ah,4ch
int 21h
main endp
end main
Example Program 2
;program to print Capital letters from a to z on each line
; program to print A to Z on each line
dosseg
.model small
.stack 100h
.data
.code
main proc
mov cx, 26
mov dx, 65
alpha:
mov ah,2
int 21h
add dx,1
mov
mov
mov
int
bx, dx ; BX will hold Dx data temporarily
dx, 10 ; new line
ah, 2
21h
mov dx,13
; carriage return
4
mov ah, 2
int 21h
mov dx, bx ; take back data from BX and return it to DX
Loop alpha
mov ah,4ch
int 21h
main endp
end main
5
Download