Professional Documents
Culture Documents
Faculty of Engineering
Division of Communications & Electronics
Inter-segment jump
JA → Jump if above, jumps when the first operand is larger than the second operand, both are treated
as unsigned numbers
JO → Jump if overflow, jumps when OF = 1
JCXZ → Jump if CX = zero.
MOV CX, AX
MOV SI, BX
MOV DI, DX
SHL AX, 1
RCL BX, 1
RCL DX, 1
ADD CX, AX
ADC BX, SI
ADC DX, DI
What is the resulting machine code of the command JMP 0109H, given that the opcode of JMP is
EBH
The difference between 0109 h and 107h is 2h is in the range of -127 to +128, so it is a short jump
Program 1 Program2
MOV AL,0FFH MOV AL,0FFH
MOV BL,01H MOV BL,01H
CMP AL,BL CMP AL,BL
JA AGAIN JG AGAIN
MOV DX,09H MOV DX,09H
JMP STOP JMP STOP
AGAIN:MOV DX,90H AGAIN:MOV DX,90H
STOP:NOP STOP:NOP
IN AL, 10 h
MOV BL, AL
IN AL, 10 h
CMP BL, AL
JG ADDNUM
SUB BL, AL
JMP EXIT
ADDNUM:
ADD BL, AL
EXIT:
HLT
b) Read two successive numbers in memory, then determine which is larger. Store the larger value
in the third memory location.
c) Read two numbers X and Y, where X is in AL and Y in AH. Determine the greater number such
that if (X > Y), calculate (X –Y), otherwise calculate (Y-X).
MOV AL, X
MOV AH, Y
CMP AL, AH
JG FIRST
SUB AH, AL
MOV AL, AH
JMP EXIT
FIRST:
SUB AL, AH
EXIT: HLT
6) Given an array A(I) with 100 8-bit signed integer numbers, write a program to generate a new
array B(I) as follows:
B(I) = A(I) for I = 1, 2, 99 and 100.
B(I) = the average of A(I-2), A(I-1), A(I), A(I+1) and A(I+2) for all others Is.
MOV AX, DI
IMUL SI
MOV CX, 100h
IDIV CX
POP DX
POP CX
POPF
RET
MyProc ENDP
b) Read a list of 5 signed numbers and determine whether each number is negative or positive. If
it is positive, do not do anything. If it is negative, call a procedure to get the absolute value of
that number. Store the absolute value in the same place of the negative number.
256
10) Explain what an INT 40 instruction does, making sure to indicate the memory location of this
vector.
Calls the interrupt vector routine at address 40x4 = 160 → A0 h
a) Pushes the flags (PUSHF)
b) Clears IF and TF
b) Pushes CS
c) Reads the new CS from [A2h] and [A3h]
d) Pushes IP
e) Reads the new IP from [A0h] and [A1h]
f) Jumps to CS:IP
Just as the far RET, it pops CS and IP from the stack. However, it also pops the flags from the stack
in order to restore the values of the IF and TF.
12) The following program defines INT 7(MULREG) as follows: AX=AX*BX-DX+CX. Trace the
program using AX=10H,BX=20H,DX=200H,CX=4FH to make sure that AX will be 4FH. If the
program contains any errors, correct it.
ORG 0001CH
DD MULREG
ORG 100h
MAIN PROC NEAR
MOV AX,10H
MOV BX,20H
MOV DX,200H
MOV CX,4FH
INT 7
HLT
MAIN ENDP
ORG 0001CH
DD MULREG
ORG 100h
MAIN PROC NEAR
MOV AX,10H
MOV BX,20H
MOV DX,200H
MOV CX,4FH
INT 7
HLT
MAIN ENDP
So it does make AX = 4Fh. But it clears DX as a side effect. So we can use MUL BL instead.
13) The following program is assumed to add the value of AX and BX and saves the result in DX
without changing the values of AX or BX. Trace the program to make sure that it DOES NOT
perform the task correctly. Correct the program to do the required task.
ORG 100h
MAIN PROC NEAR
CS:100 MOV SP,100H
CS:103 MOV AX,20H
CS:106 MOV BX,30H
CS:109 MOV DX,3FH
CS:10C PUSH AX
CS:10D PUSH BX
CS:10E CALL ADDREG
CS:111 MOV DX,AX
CS:113 POP BX
CS:114 POP AX
CS:115 MOV CX,35H
CS:118 HLT
MAIN ENDP
ORG 100h
MAIN PROC NEAR
CS:100 MOV SP,100H
SP = 0100h
CS:103 MOV AX,20H
AX = 0020 h
CS:106 MOV BX,30H
BX = 0030 h
CS:109 MOV DX,3FH
DX = 003Fh
CS:10C PUSH AX
SP = 00FE h
[FE] = 20 h
[FF] = 00 h
CS:10D PUSH BX
SP = 00FC h
[FC] = 30h
[FD] = 00 h
CS:10E CALL ADDREG
SP = 00FA h
[FA] = 11 h
[FB] = 01 h
IP = ADDREG
CS:111 MOV DX, AX
DX = 0050 h
CS:113 POP BX
BX = 0030 h
SP = 00FE h
CS:114 POP AX
AX = 0020 h
SP = 0100 h
CS:115 MOV CX,35H
CX = 0035 h
CS:118HLT
MAIN ENDP
----------------------------------------------------------------------------------------------------------------------------------