在我的程序中,你会看到这样的东西:
000000000000001000000010000000010
但我想要这样的东西(更容易阅读):
00000000 00000100 000001000 00000100
(这只是一个例子)
我该怎么做?我相信我需要在PUT_BIN程序中改变一些东西,但我不知道是什么。 这是我的代码:
PAGE 80,132
;===================================================================
; PROGRAM LISTING 5.1
;
;PROGRAM TO DEMONSTRATE SUBROUTINE INTERFACE
;
;===================================================================
.MODEL SMALL,BASIC,FARSTACK
;===================================================================
;PROCEDURES TO
EXTRN NEWLINE:FAR ;DISPLAY NEWLINE CHARACTER
EXTRN PUTDEC:FAR ;DISPLAY DECIMAL INTEGER
;===================================================================
; S T A C K D E F I N I T I O N
;
.STACK 256
SHL32 MACRO REG1, REG2
SHL REG2, 1
RCL REG1, 1
ENDM
SHR32 MACRO REG1, REG2
SHR REG1, 1
RCR REG2, 1
ENDM
;===================================================================
; C O D E S E G M E N T D E F I N I T I O N
;
.CODE
;
EX_5_1:
MOV BL,1
MOV DI,0001H
MOV SI,0010H
MOV DL,1
MOV AX, DI
CALL PUT_BIN
MOV AX, SI
CALL PUT_BIN
CALL NEWLINE
SHL32 DI,SI
MOV AX, DI
CALL PUT_BIN
MOV AX, SI
CALL PUT_BIN
CALL NEWLINE
;
;
SHR32 DI,SI ;
MOV AX, DI
CALL PUT_BIN
MOV AX, SI
CALL PUT_BIN
CALL NEWLINE
CALL NEWLINE ;SKIP TO NEXT LINE ON DISPLAY
.EXIT ;RETURN TO DOS
;
PAGE
;===================================================================
; PROCEDURE TO DISPLAY AN 8- OR 16-BIT VALUE IN BINARY FORM
;
; INPUT: AL-REG 8-BIT VALUE TO BE DISPLAYED
; BL=0 CODE FOR 8-BIT DISPLAY
; OR
; AX-REG 16-BIT VALUE TO BE DISPLAYED
; BL<>0 CODE FOR 16-BIT DISPLAY
;
; OUTPUT: INPUT VALUE DISPLAYED IN BINARY FORM ON THE
; SCREEN BEGINNING AT CURRENT CURSOR POSITION
;===================================================================
PUT_BIN PROC NEAR ;PROCEDURE PUTBIN(NUMBER,CODE)
PUSH AX ;SAVE REGISTERS
PUSH DX
PUSH DI
PUSH BX
PUSH CX
PUSHF ;SAVE FLAGS
CMP BL,0 ;IF CODE = BYTE (BL=0)
JNZ _ELSE
MOV AH,0 ;THEN EXPAND NUMBER TO 16 BITS
MOV CX,8 ; BIT_COUNT = 8
JMP _ENDIF
_ELSE: ;ELSE
MOV CX,16 ; BIT_COUNT = 16
_ENDIF: ;ENDIF
MOV BX,2
MOV DI,CX ;SAVE BIT_COUNT
LOOPTOP: ;REPEAT
MOV DX,0 ; BIT = NUMBER mod 2
DIV BX ; NUMBER = NUMBER / 2
PUSH DX ; PUSH BIT
LOOP LOOPTOP ; DECREMENT BIT_COUNT
;UNTIL BIT_COUNT = 0
MOV CX,DI ;RESTORE BIT_COUNT
MOV BH,0 ;<DISPLAY CODE>
_REPEAT: ;REPEAT
POP AX ; POP BIT
CALL PUTDEC ; DISPLAY BIT
LOOP _REPEAT ; DECREMENT BIT_COUNT
;UNTIL BIT_COUNT = 0
POPF ;RESTORE FLAGS
POP CX ;RESTORE REGISTERS
POP BX
POP DI
POP DX
POP AX
RET ;RETURN
PUT_BIN ENDP ;END PUTBIN
END EX_5_1
答案 0 :(得分:1)
在
...
_REPEAT:
插入类似
的内容 test cx, 7 ;test if loop counter can be divided by eight
jnz nospace
mov al, 32 ;a space
call PUTCHAR
nospace:
之后,旧程序继续。
POP AX
...
我不知道PUTCHAR子程序是否存在,也不知道它使用的是什么寄存器或clobberes。我只是假设它使用AL作为输入寄存器并保存所有内容。