当前位置:
文档之家› 微型计算机原理第2版西安电子科技大学出版社第五章汇编语言程序设计课后习题答案
微型计算机原理第2版西安电子科技大学出版社第五章汇编语言程序设计课后习题答案
DATA ENDS CODE SEGMENT
ASSUME CS:CODE,DS:DATA START:MOV AX,DATA
MOV DS,AX LEA DX,INFOR0 MOV AH,9 INT 21H XOR BX,BX MOV CH,04 MOV CL,04 INPUT: SHL BX,CL MOV AH,01 INT 21H CMP AL,30H JB ERROR CMP AL,39H JA NEXT AND AL,0FH JMP BINARY NEXT: CMP AL,41H
mov ax,di mov ch,10 div ch mov dl,al mov bh,ah ADD DL,30H MOV AH,2 INT 21H mov dl,bh ADD DL,30H MOV AH,2 INT 21H mov ah,4ch
int 21h
CODE ENDS END START
MOV BL,LENGTH TABLEB
;(BL)=0AH
MOV CL,LENGTH TABLEC
;(CL)=01H
6、对于下面的数据定义,各条 MOV 指令单独执行后,有关寄存器的内容 是什么?
PLDB DB ? TABLEA DW 20 DUP(?) TABLEB DB ‘ABCD’
;答:
(1) MOV AX,TYPE PLDB
ASSUME CS:CODE,DS:DATA START:MOV AX,DATA
MOV DS,AX mov bx,0 MOV SI,0 MOV DI,0 MOV CX,20 again: cmp M[bx],0 jl less je again inc si jmp next less: inc di
24、设有字无符号数 X、Y,试编制求 Z=丨 X-Y 丨的程序。
11. DATA SEGMENT
Infor1 DB 'Please input string1:',0AH,0DH,'$' STR1 DB 12,0,10 DUP (0) Infor2 DB 0AH,0DH,'Please input string2:',0AH,0DH,'$' STR2 DB 12,0,10 DUP (0) Infor3 DB 0AH,0DH,'MATCH',0AH,0DH,'$' Infor4 DB 0AH,0DH,'NO MATCH',0AH,0DH,'$' DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START:MOV AX,DATA
BYTE_VAR 42H
WORD_VAR 00H
07H
59H
00H
00H
54H
01H
FBH
45H
00H
FFH
0CH
02H
59H
EEH
00H
42H
00H
00H
45H
07H
00H
54H
01H
01H
56H
02H
00H
02H
01H
02H
02H
00H
07H
00H
00H00H
02H
02H
JAE CONTINE JMP ERROR CONTINE: CMP AL,46H JA CONTINE2 JMP PROCESS CONTINE2: CMP AL,61H JAE CONTINE3 JMP ERROR CONTINE3: CMP AL,66H JA ERROR PROCESS: AND AL,0FH ADD AL,09H BINARY: OR BL,AL DEC CH JNE INPUT LEA DX,INFOR2 MOV AH,9 INT 21H DISPN: MOV CX,16 DISP: MOV DL,0 ROL BX,01 RCL DL,01 OR DL,30H MOV AH,02 INT 21H LOOP DISP JMP Exit
EX515.ASM
DATA SEGMENT INFOR0 DB 0AH,0DH,"please input a four hex number",0AH,0DH,'$' INFOR DB 0AH,0DH,"invalid hex digital",0AH,0DH,'$' INFOR2 DB 0AH,0DH,"convert binary is:",0AH,0DH,'$'
MOV DX,OFFSET Infor4 MOV AH,9 INT 21H ReturnDOS: MOV AH,4CH INT 21H CODE ENDS END START
EX513b DATA SEGMENT
M DB 1,2,3,4,5,6,-7,-8,-9,-10,11,12,13,14,15,-16,-17,-18,-19,-20 P DB 20 DUP(0) N DB 20 DUP(0) CountP DB 0 CountN DB 0 DATA ENDS CODE SEGMENT
(1) 用一条 MOV 指令将 LNAME 的偏移地址存入 BX。 (2) 用一条指令将 CODE_LIST 的头两个字节的内容放入 SI。 (3) 写一条伪指令定义符使 CODE_LENGTH 的值等于 CODE_LIST 域的实
际长度。
答:(1) MOV BX,OFFSET LNAME (2) MOV SI,WORD PTR CODE_LIST
;(AX)=0001H
(2) MOV AX,TYPE TABLEA
;(AX)=0002H
(3) MOV CX,LENGTH TABLEA ;(CX)=0014H
(4) MOV DX,SIZE TABLEA
;(DX)=0028H
(5) MOV CX,LENGTH TABLEB ;(CX)=0001H
7、试说明下述指令中哪些需要加上 PTR 伪指令定义符。
EX511b.ASM DATA SEGMENT
Infor1 DB 'Please input string1:',0AH,0DH,'$' Infor2 DB 0AH,0DH,'Please input string2:',0AH,0DH,'$' STR1 DB 12,0,10 DUP (0) STR2 DB 12,0,10 DUP (0) Infor3 DB 0AH,0DH,'MATCH',0AH,0DH,'$' Infor4 DB 0AH,0DH,'NO MATCH',0AH,0DH,'$' DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START:MOV AX,DATA
第五章 汇编语言程序设计
1、画图说明下列语句所分配的存储器空间及初始化的数据值。
(1) BYTE_VAR DB ‘BYTE’,12,-12H,3 DUP(0,7, 2 DUP(1,2),7)
(2) WORD_VAR DW 5 DUP(0,1,2),7,-5,’BY’,’TE’,256H
答:(1)
(2)
MOV DS,AX MOV ES,AX
LEA SI,STR1 LEA DI,STR2 MOV DX,OFFSET Infor1 MOV AH,9 INT 21H MOV DX,OFFSET STR1 MOV AH,0AH INT 21H MOV DX,OFFSET Infor2 MOV AH,9 INT 21H MOV DX,OFFSET STR2 MOV AH,0AH INT 21H INC SI INC DI MOV AL,[SI] MOV AH,[DI] CMP AH,AL JNZ NOSAME MOV AH,0 MOV CX,AX INC SI INC DI CLD COMPARE: REPE CMPSB JNE NOSAME SAME: MOV DX,OFFSET Infor3 MOV AH,9 INT 21H JMP ReturnDOS NOSAME:
BVAL DB 10H,20H
WVAL DW 1000H
;答:
(1) MOV AL,BVAL
;
(2) MOV DL,[BX]
;
(3) SUB [BX],2
;SUB [BX],WORD PTR 2
; SUB BYTE PTR [BX],2
(4) MOV CL,WVAL
;MOV CL,BYTE PTR WVAL
01H
00H
02H
00H
07H
00H
00H
01H
07H
00H
01H
02H
02H
00H
01H
00H
02H
00H
07H
01H
00H
02H
00H
2、假设程序中的数据定义如下:
PARTNO DW ? PNAME DB 16 DUP(?) COUNT DD ?
PLENTH EQU $- PARTNO
问:PLENTH 的值为多少?他表示什么意义? 答:PLENTH 的值为 22,它表示当前已分配单元空间。 3、有符号定义语句如下:
next: inc bx dec cx jnz again
show: mov ax,si mov ch,10 div ch mov dl,al mov bh,ah ADD DL,30H MOV AH,2 INT 21H mov dl,bh ADD DL,30H MOV AH,2 INT 21H mov dl,2ch mov ah,2 int 21h