《微机原理与接口技术》 (张凡 盛珣华 戴胜华 著) 清华大学出版社 北方交通大学出版社 课后答案 下载本文

ASSUME CS:CODE, DS:DATA,SS:STACK1 START: MOV AX, DATA MOV DS, AX MOV AL, XX CMP AL, -1 JG BIGR MOV AL, -1 JMP JUST2 BIGR: CMP AL, 1 JGE JUST1 MOV AL, 0 JMP JUST2 JUST1: MOV AL, 1 JUST2: MOV Y, AL MOV AH, 4CH INT 21H CODE ENDS

END START

4-17 将内存中某数据块中的正数和负数分开,并分别将这些正数和负数送同一

数据段的两个缓冲区中,并在屏幕上显示正数和负数的个数. DATA SEGMENT

D1 DB -1, -2, 1, 2, 3, -4, 4,5,-5,0,0,9,-3 COUNT EQU $-D1

D2 DB 100 DUP(?) D3 DB 100 DUP(?) PNUM DW 1 DUP(?) NNUM DW 1 DUP(?)

CONST DW 10000,1000,100,10,1 DECS DB 5 DUP(0)

HEAD1 DB 'THE NUMBER OF POSITIVE NUMBER IS:$' HEAD2 DB 'THE NUMBER OF NEGATIVE NUMBER IS:$' DATA ENDS

STACK1 SEGMENT PARA STACK DB 100 DUP(0) STACK1 ENDS

CODE SEGMENT

ASSUME CS:CODE, DS:DATA,SS:STACK1 START: MOV AX, DATA MOV DS, AX

MOV BX, OFFSET D1 MOV SI, OFFSET D2

MOV DI, OFFSET D3 MOV CX, COUNT LOP: MOV AL, [BX] CMP AL, 0 JGE JUST1 MOV [DI], AL INC DI INC NNUM JMP JUST2 JUST1: JE JUST2 MOV [SI], AL INC SI INC PNUM JUST2: INC BX DEC CX JNZ LOP

MOV AH,9H

MOV DX,OFFSET HEAD1 INT 21H

MOV AX,PNUM

MOV DL,0AH MOV AH,02H INT 21H

MOV DL,0DH MOV AH,02H INT 21H

MOV AH,9H

MOV DX,OFFSET HEAD2 INT 21H

MOV AX,NNUM CALL DISPLAY

MOV DL,0AH MOV AH,02H INT 21H

MOV DL,0DH MOV AH,02H INT 21H

MOV AH, 4CH

INT 21H

DISPLAY PROC NEAR MOV CX,5 LEA SI,CONST LEA DI,DECS CONV3: MOV BL,0 LOP1: SUB AX,[SI] JC NEXT INC BL JMP LOP1 NEXT: ADD AX,[SI] OR BL,30H MOV [DI],BL INC SI INC SI INC DI LOOP CONV3

MOV AH,02H MOV CX,5 LEA DI,DECS CONV4: MOV DL,[DI]

CMP DL,30H JZ NODIS JMP DISP NODIS: INC DI LOOP CONV4 DISP: INT 21H CMP CX,0 JZ QUIT INC DI

MOV DL,[DI] LOOP DISP QUIT: RET DISPLAY ENDP

CODE ENDS

END START

4-19 内存BLOCK开始,存放着256个字节的带符号数.编写程序,从这些数中找出

绝对值最大的数,将其放入MAX中. 解:

DATA SEGMENT

BLOCK DB -1, -3, 2, 5, -4, -7, -8,9,10,-124 COUNT EQU $-BLOCK MAX DB ? MAX1 DB ?

DATA ENDS

STACK1 SEGMENT PARA STACK DB 100 DUP(0) STACK1 ENDS CODE SEGMENT

ASSUME CS:CODE, DS:DATA,SS:STACK1 START: MOV AX, DATA MOV DS, AX

MOV SI, OFFSET BLOCK MOV CX, COUNT MOV BL,[SI] CMP BL, 0 JL ABS1 JMP CON1 ABS1: NEG BL CON1: DEC CX LOP: INC SI MOV AL,[SI] CMP AL, 0 JL ABS2 JMP CON2 ABS2: NEG AL

CON2: CMP BL, AL JAE JUST1 XCHG BL, AL MOV DI,SI JUST1: DEC CX JNZ LOP MOV BH,[DI] MOV MAX,BH MOV MAX1, BL MOV AH, 4CH INT 21H CODE ENDS

END START