Sheet Ch:10

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

SHEET CH:10

1) Assume the real mode. If (DS) = 1000H, (SS) = 2000H, (CS) = 3000H,
(BP) = 000FH, and (BX) = 000AH before execution of the following
Pentium instructions:
(a) MOV CX,[BX] 20-bit physical address=0000A H+10000 H=1000A H

(b) MOV DX,[BP] 20-bit physical address=0000F H+20000 H=2000F H

Find the 20-bit physical address after execution of each of the instructions above.

2) If (DS) = 205FH and OFFSET = 0052H, what is the 20-bit physical address
in real mode?
20-bit physical address=205F0H+00052H=20642H

3) In a Pentium system in real the mode, segments land 2 both contain


addresses 00100H & 0200H. What are these segments called?

Start segment1=0100+0000=0100 H
End segment1=0100+FFFF=100FF H

Start segment2=0200+0000=0200 H
End segment2=0200+FFFF=101FF H

So they share the common segment from 0200 H to 100FF H


So they are partially overlapped.

4) Determine the addressing modes for the following Pentium instructions:


(a) CLC Implied addressing mode
(b) CALL WORDPTR[BX] Indirect addressing mode
(c) MOV AX,DX Register addressing mode
(d) ADC EBX,[EAX+4*ESI+2000H] Indirect Based Indexed(with scaling)

5) XXXX
6) Determine the effect after execution of instructions:
(a) MOVZX EAX,CH
Each of the following Pentium Prior to execution of this MOVZX
instruction, assume
(EAX) = 80001234H
(ECX) = 00008080H
So CH=80H  EAX=00000080H
(b) MOVSX EDX,BL
Prior to execution of this MOVSX assume
(EDX) = FFFFFFFFH
(EBX) = 05218888H
So BL=88H  EDX=FFFFFF88H

7) Find the overflow, direction, interrupt, trap, sign, zero, parity, and carry flags
after execution of the following Pentium instruction sequence:
MOV AH, OF H AH=0F H
SAHF  STORE AH IN FLAGES
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 NT OF DF IF TF SF ZF 0 AF 0 PF 1 CF
0 0 0 0 1 1 1 1
0 F

So we obtain CF=1, PF=1, AF=0, ZF=0, SF=0;

8) What is the content of AL after execution of the following Pentium


instruction sequence?
MOV BH,33H  BH=33H
MOV AL,32H  AL=32H
ADD AL,BH  AL=65H
AAA  AL=05H

9) What happens after execution of the following Pentium instruction


sequence? Comment.

MOV DX,OOlFH  DX=001FH


XCHG DL,DH DX=1F00H
MOV AX,DX AX=1F00H
IDIV DL DL=00H So there are internal interrupt for CPU
10) What are the remainder, quotient, and registers containing them after
execution of the following Pentium instruction sequence?
MOV AH,O  AH=00H
MOV AL,OFFH  AL=FFH==> AX=00FFH
MOV CX,2  CX=0002H
IDIV CL  00FF H/02 H  255 D/2 D  quotient=127 D,
remainder=1 D AH=01H, AL=7EH  AX=017E.

11) Determine the effect after execution of each of the following


Pentium instructions.
(a) CDQ  Sign extend for EDX by EAX  EAX=FFFFFFFFH,
EDX=FFFFFFFFH
(b) MOVSX ECX, E7H  ECX=FFFFFFE7H
Assume (EAX) = FFFFFFFFH, (ECX) = F1257124H, and
(EDX) = EEEEEEEEH prior to execution of each of these instructions.

12) Write the Pentium instruction sequence to clear the trap flag in the
FLAGS register without affecting the other flags.

PUSHF  Push 16-bit from stack into flags


POP AX  Pop 16-bit on AX
AND AX, FEFF H
PUSH AX  Push AX on stack
POPF  Pop top of stack into flags
13) Write a Pentium assembly program to find the minimum value of a
string of 10 signed 8-bit numbers using indexed addressing. Assume that
offset 5000H contains the first number.
MOV BX, 5000H
MOV AL,[BX]
MOV CX,10
L3: CMP AL,[BX]
JG L1
JMP L2
L1: MOV AL,[BX]
L2: INC BX
LOOP L3
HLT

14) Write a Pentium assembly language program that will convert a BCD
number in AL to a seven-segment code using a look-up table containing the
seven-segment codes of the BCD numbers. Use a common-cathode display.
Assume that the table is stored in memory starting at offset 2000H. Use the
XLAT instruction. Initialize DS to 3000H
.486
.data
Org 2000h
db 3fh
db 06h
.
.
.code
Push ax
Mov ax,3000h
Mov ds, ax
Mov bx, 2000h
Pop ax
xlat
15) Write a Pentium assembly program to add a 64-bit number in ECX:
EDX with another 64-bit number in EAX: EBX. Store the result in EAX:
EDX.
Add edx,ebx
Adc eax,ecx

16) Write a Pentium assembly language program to subtract two 64-bit


numbers Assume that SI and DI point to the low words of the numbers
Mov ebx,dword prt[si]
Add si,4
Mov eax,dword prt[si]
Mov ecx,dword prt[di]
Add di,4
Mov edx,dword prt[di]
Sub ebx,ecx
Sbb eax,edx

17) Write a Pentium assembly program to add a 16-bit number stored in


BX (bits 0 to 7 containing the high-order byte of the number and bits 8 to
15 containing the low-order byte) with another 16-bit number stored in CX
(bits 0 to 7 containing the low-order 8 bits of the number and bits 8
thorough 15 containing the high- order 8 bits). Store the result in AX.
MOV AH, BL
MOV AL, BH
ADD AX, CX
OR
XCHG BH, BL
ADD BX, CX
MOV AX, BX
18) Write a Pentium assembly program to add twenty five 16-bit numbers
stored in consecutive memory locations starting at displacement 0100H in
DS = 0020H. Store the 16-bit result onto the stack. Initialize SS to 2000H,
SP to 1000H, and DS to 0020H.

MOV AX, 0020H


MOV DS, AX
MOV AX, 2000H
MOV SS, AX
MOV SP, 1000H
MOV BX, 0100H
MOV AX, 0
MOV CX, 25D
L1: ADD AX, [BX]
Add bx,2
LOOP L1
PUSH AX
HLT

19) Write a Pentium assembly language program to subtract a 24-bit


number (x) stored in low 24 bits of EAX from another 24-bit number (y)
stored in consecutive memory locations starting at offset 6080H in BX (the
highest byte at 6082H and the lowest byte at 6080H). Store the 24-bit result
in the low 24 bits of EAX; ignore the highest byte of EAX.

Mov bx,6080h
sub al,byte ptr[bx] ; sub the first bytes
pushf
Inc bx
popf
sbb ah,byte ptr[bx] ; sub the second bytes with borrow
Pushf ;store the sub operation effect on flags
Mov cx,ax ;store result of 2 bytes
Shr eax,16 ;the third byte now in al
Inc bx
Popf
sbb al,byte ptr[bx] ; sub the third bytes with borrow
Pushf ;store the sub operation effect on flags
Shl eax,16 ;mov the third byte in result back
Mov ax,cx ; store result of 2 bytes back
Popf ;restore flag

20) If (EBX) = 0123A212H and (EDX) = 46B12310H, then what are the
contents of EBX and EDX after execution of the Pentium instruction
XADD EBX,EDX?

This instruction will exchange and adding 


0123A212H + 46B12310H  EBX=47D4C522H
And EDX will be the original EBX before addition EDX=0123A212H

21) If (BX) = 271AH, (AX) = 712EH, and (CX) = 1234H, what are the
contents of AX after execution of the Pentium instruction
CMPXCHG CX.BX?

[AX]!=[CX]
So AX=CX=1234H
BX=271AH as it is.
CX=1234H as it is.
22) Write a Pentium assembly language program to perform (X2 + Y2)
where X is a signed 8-bit number stored in CL and Y is an unsigned 16-bit
number stored in low 16 bits of SI. Save the 32-bit result onto the stack.
Assume SP is already initialized.
Mov al,cl
Imul cl ;now ax=cl*cl
push ax ; store result of cl*cl in stack
Mov ax,si
mul si ; now dx:ax=si*si
Mov bx,ax
Mov cx,dx ; store result of si*si in cx:bx
Pop ax ;restore result of cl*cl from stack
Cwd ;extend the ax >>dx:ax
Add ax,bx
Adc dx,cx
Push ax

23) Write a Pentium assembly language program to multiply a 16-bit


signed number stored in AX by an 8-bit unsigned number stored in the low
BL.Store the 32-bit result in BX:CX.

Movzx cx,bl ;extend unsigned 8 bit # to 16 bit


Imul cx
Mov cx,ax ;
Mov bx,dx
24) Assume that AL, CX,and DXBX contain a signed byte, a signed word,
and a signed 32-bit number, respectively. Write a Pentium assembly
language program that will compute the signed 32-bit result: AL - CX +
DXBX >> DXBX
Cbw ;extend signed number in al to ax
Sub ax,cx ;now ax=al-cx
Push dx ;store dx in stack because the next instruction will effect dx
Cwd ; extend signed number in axl to dx:ax
Mov cx,dx ;now cx:ax=al-cx
Pop dx
Add bx,ax
Adc dx,cx

25) Write a Pentium assembly language program to multiply a signed 8-


bit number in AL by a signed 32-bit number in ECX. Store 64-bit result in
EDX:EAX

Cbw ;extend signed number in al to ax


Cwd ; extend signed number in axl to dx:ax
Imul ecx

26) Write a Pentium assembly program to multiply the top two 16-bit
unsigned words of the stack. Store the 32-bit result onto the stack. Initialize
SS to 5000H and SP to 0020H

Mov ax,5000
Mov ss,ax ; Initialize ss
Mov sp,0020 ; Initialize sp
Pop ax
Pop cx
Mul cx
Push ax
Push dx

27) Write a Pentium assembly language program to convert 255 degrees


in Celsius in BL to Fahrenheit degrees and store the value in AX. Use the
equation F= (C/5) * 9 + 32
Mov al,255d
mov cl,9
mul cl ;now ax=255*9
cwd ; extend ax to dx:ax prepare for div
mov cx,5
div cx ;now dx:ax =255*9/5
add ax,32d

28) Write a Pentium assembly program to divide an 8-bit signed number


in CH by an 8-bit signed number in CL. Store the quotient in CH and the
remainder in CL.

Mov al,ch
Cbw
Idiv cl
Mov ch,al
Mov cl,ah

29) Write a Pentium assembly program to divide a signed 32-bit number


in DX:AX by an 8-bit unsigned number in BH. Store the 16-bit quotient and
16-bit remainder in DX and AX respectively.

Movzx cx,bh ;move with zero extend the unsigned bh to cx


Idiv cx
Xchg dx,ax

You might also like