bài tập nhúng c8

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Chap 6 

1. Show how the 80x86 computer would represent the following


numbers and  verify each with DEBUG 
a. -23 E9  b. +12 0C  c. -28 E4  d. +6FH 6F
e. -128 80  f. +127 7F  g. +365 16D  h. -32767 8001

2. Find the overflow flag for each case and verify the result using DEBUG 
a. (+15)+(-12) OF = 0  b. (-123)+(-127) OF = c. (+25h)+(+34) OF = 0 
result = 03 1  result = 06 result = 47H
d. (-127)+(+127) OF = 0 result
e. (+1000)+(-1000)
= 00 OF = 0 result = 00

3. Sign-extend the following and write simple program in DEBUG to verify


them 
a. -122  b. -999h  c. +17h 
MOV AL,-122 ;AL MOV AX,-999H ;AX MOV AL,17H ;AL
= 86 CBW ;AX = = F667 CWD ;DX = = 17 CBW ;AX =
FF86 FFFF 0017
d. +127  e. -129 
MOV AL,127 ;AL MOV AX,-129 ;AX
= 7F CBW ;AX = = FF7F CWD ;DX
007F = FFFF

5. Which instructions are used to set and reset the direction flag? State
the purpose  of the direction flag. 
- STD: để thiết lập DF = 1 
- CLD: xóa DF, DF = 0 
- Cờ hướng là cờ điều khiển hướng xử lý chuỗi từ trái sang phải hoặc từ
phải sang trái, nếu DF = 0, con trỏ (DI và SI) sẽ tăng, nếu DF = 1,
con trỏ  
sẽ giảm. 
6. The REP instructions can be used with which of the following
instructions? 
a. MOVSB  b. MOVSW  c. CMPSB
d. LODSB  e. STOSW  f. SCASW

8. Write and verify a program that transfers a block of 200 words of data. 

 .MODEL SMALL 
 .STACK 64 
 .DATA 
DATA1 DW 200 DUP('AA') 
DATA2 DW 200 DUP(?)
 .CODE 
MAIN PROC FAR 
MOV AX, @DATA 
MOV DS, AX 
MOV ES, AX 
CLD 
MOV SI, OFFSET DATA1 
MOV DI, OFFSET DATA2 
MOV CX, 200 
REP MOVSW 
MOV AH, 4CH 
INT 21H 
MAIN ENDP 
END MAIN 
9. Use instructions LODSx and STOSx to mask the 3 from a set of 50
ASCII digits  and transfer the result to a different memory location. This
involves converting  from ASCII to unpacked BCD, then storing it at a
different location, for example source destination 
ASCII for “5” 0011 0101 0000 0101 

 .MODEL SMALL 
 .STACK 64 
 .DATA 
DATA1 DB 50 DUP(‘A’) 
DATA2 DW 50 DUP(?) 
 .CODE 
MAIN PROC FAR 
MOV AX, @DATA 
MOV DS, AX 
MOV ES, AX 
MOV AH, 3 
CLD 
MOV SI, OFFSET DATA1 
MOV DI, OFFSET DATA2
MOV CX, 20 
LOOP: 
LODSB 
STOSB 
MOV [DI]+1, AH 
ADD DI, 2 
ADD SI, 1 
CMP CX, 0 
JNZ LOOP 
MOV AH, 4CH 
INT 21H 
MAIN ENDP 
END MAIN 
10. Which prefix is used for the inequality case for CMPS and SCAS instructions? 

REPE/REPNE 
11. Write a program that scans the initials “IBM” and replaces the
lowercase “b”  with uppercase “B”. 
 .MODEL SMALL 
 .STACK 64 
 .DATA 
DATA1 DB 'IBM' 
 .CODE 
MAIN PROC FAR 
MOV AX, @DATA 
MOV ES, AX 
MOV DS, AX 
CLD 
MOV DI, OFFSET DATA1 
MOV CX, 03 
MOV AL, 'b' 
REPNE SCASB 
CMP [DI]- 1, 'b' 
JNZ EXIT
MOV [DI] -1, 'B' 
EXIT: 
MOV AH, 4CH 
INT 21H 
MAIN ENDP 
END MAIN 
13. Write a program using a look-up table and XLAT to retrieve the y
value in the  equation y = 
x2 + 2x + 5 for x values of 0 to 9. 

 .MODEL SMALL 
 .STACK 64 
 .DATA 
DATA1 DB 9,8,7,6,5,4,3,2,1,0 
RESULT DB ? 
 .CODE 
MAIN PROC FAR 
MOV AX, @DATA 
MOV DS, AX 
MOV BX, OFFSET DATA1 
MOV CL, 09 
LTB: 
MOV DL, 5 
MOV AL, CL 
XLAT 
ADD DL, AL 
ADD DL, AL 
MUL AL 
ADD DL, AL 
MOV RESULT, DL 
SUB CL, 1 
CMP CL, 0 
JNZ LTB 
EXIT:
MOV AH, 4CH 
INT 21H 
MAIN ENDP 
END MAIN 
13. Write a program using a look-up table and XLAT to retrieve the y
value in the  equation y = x + 2x + 5 for x values of 0 to 9.
2

You might also like