Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
325 views7 pages

Chp#3Ex: A. JG Greater B. JL Smaller C. Ja Above D. JB Below

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 7

CHP#3EX

1. Which registers are changed by the CMP instruction?


ANS: The Overflow, Sign, Zero, Auxiliary Carry, and Parity flags are changed The PUSHAD
instruction pushes all of the 32-bit general- purpose registers on the stack in In x86 assembly
language we use the CMP instruction to compare integers.

2. What are the different types of jumps available? Describe position


relative addressing.?
ANS: A jump instruction, like jmp just switches the CPU to executing a different piece of code.
It's the assembly equivalent of goto but unlike goto, jumps are notconsidered shameful
in assembly. Under unconditional jump instructions there is only one mnemonic i.e. JUMP. But
under conditional Jump instructions we are having 8 different mnemonics. We know that there
are 5 flag bits in 8085 Flag register. They are S, Z,P, Cy, AC. Out of them only on AC flag bit,
there is no jump instruction.
Relative addressing is the technique of addressing instructions and data areas by designating
their location in relation to the location counter or to some symbolic location. This type
of addressing is always in bytes never in bits, words, or instructions.

3. If AX=8FFF and BX=0FFF and “cmp ax, bx” is executed, which of the following
jumps will be taken? Each part is independent of others. Also give the value of Z,
S, and C flags.?
a. jg greater

b. jl smaller

c. ja above

d. jb below

Instructions Jump ZF SF CF
Jg greater Not taken 0 1 0
Jl smaller Taken 0 1 0
Ja above Taken 0 1 0
Jb below Not taken 0 1 0

Umar Asghar-70076360
CHP#3EX

3. Write a program to find the maximum number and the minimum number
from an array of ten numbers.?
[org 0x0100]
jmp start

array1: dw 10, 5, 30, 4, 50, 1, 20, 6, 40, 8


min: dw 0
max: dw 0

start:

mov bx, 0
mov ax, 0

mov ax, [array1+bx]


mov cx,10
top1: cmp ax, [array1+bx]
jle end1
mov ax,[array1+bx]
end1:
add bx, 2
loop top1

mov [min], ax

Umar Asghar-70076360
CHP#3EX

mov bx, 0
mov ax, 0
mov ax, [array1+bx]
mov cx,10

top2: cmp ax, [array1+bx]


jge end2
mov ax,[array1+bx]
end2:
add bx, 2
loop top2

mov [max], ax
mov ax, 0x4c00
int 0x21

6. Write a program to calculate the factorial of a number where factorial?

INCLUDE io.h

Cr EQU 0ah
Lf EQU 0dh

Umar Asghar-70076360
CHP#3EX

data SEGMENT
p_n DB cr, lf, 'Enter n: ',0
p_res DB cr, lf, 'The factorial is: ',0
tmpstr DW 40 DUP (?)
data ENDS

code SEGMENT
ASSUME cs:code, ds:data
start: mov ax, data
mov ds, ax
;input n1
output p_n
inputs tmpstr, 10
atoi tmpstr
;initialize
mov bx, ax
mov ax, 01h
;factorial iterations
n_ip: imul bx
dec bx
jnz n_ip
;output factorial

Umar Asghar-70076360
CHP#3EX

output p_res
itoa tmpstr, ax
output tmpstr

quit: mov al, 00h


mov ah, 4ch
int 21h
code ENDS
END start

4. Write a program to search a particular element from an array using binary


search. If the element is found set AX to one and otherwise to zero.?
DATA SEGMENT
STRING1 DB 11H,22H,33H,44H,55H
MSG1 DB "FOUND$"
MSG2 DB "NOT FOUND$"
SE DB 33H
DATA ENDS

PRINT MACRO MSG


MOV AH, 09H
LEA DX, MSG
INT 21H
INT 3
ENDM

Umar Asghar-70076360
CHP#3EX

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AL, SE
LEA SI, STRING1
MOV CX, 04H

UP:
MOV BL,[SI]
CMP AL, BL
JZ FO
INC SI
DEC CX
JNZ UP
PRINT MSG2
JMP END1

FO:
PRINT MSG1

END1:

Umar Asghar-70076360
CHP#3EX

INT 3
CODE ENDS
END START

Umar Asghar-70076360

You might also like