装配基础:输出寄存器值

时间:2015-12-13 18:07:26

标签: assembly dos x86-16 emu8086

我刚刚开始学习汇编语言,我已经停留在“显示存储在屏幕上的寄存器中的十进制值”的部分。我使用emu8086,任何帮助将不胜感激! :)

.model small  ;Specifies the memory model used for program to identify the size of code and data segments

org 100h      ;allocate 100H memory locations for stack

.data         ;the segment of the memory to declare/initialze the variables

var1 db 0006
var2 db 0002
var3 db 0001


.code           ;start of the code segment

main proc       ;start of the first procedure

mov bl, var1
add bl, var2
add bl, var3


mov ah, 00h   ; display  function here?
mov dl, bl    ; output the bl register's value?  
int 21h

mov ah, 4ch  ;exit DOS function                                           
int 21h

endp         ;end of the first procedure

end main     ;end of the complete assembly program

ret

2 个答案:

答案 0 :(得分:3)

mov ah, 00h   ; display  function here?

不,单字符显示功能位于AH=2 / int 21h

由于你的BL寄存器只包含一个小值(9),所以它只需要:

mov  ah, 02h
mov  dl, bl
add  dl, "0"   ; Integer to single-digit ASCII character
int  21h

如果值变得有点大但不超过99,您可以使用:

mov  al, bl
aam               ; divide by 10: quotient in ah, remainder in al (opposite of DIV)
add  ax, "00"
xchg al, ah
mov  dx, ax
mov  ah, 02h
int  21h
mov  dl, dh
int  21h

答案 1 :(得分:2)

在emu8086中,您可以使用现成的宏和过程来实现此目的。

示例:

include 'emu8086.inc'       ; Include useful macros and procedures

.model small

.stack

.data

var1 db 6
var2 db 2
var3 db 7

.code

DEFINE_PRINT_NUM         ; Create procedure PRINT_NUM          
DEFINE_PRINT_NUM_UNS     ; Create procedure PRINT_NUM_UNS

crlf proc
    mov ah, 2
    mov dl, 13
    int 21h
    mov dl, 10
    int 21h
    ret
crlf endp

main proc

    mov ax, @data
    mov ds, ax

    ; test output: 54321 & -11215 
    mov ax, 54321
    call PRINT_NUM_UNS   ; Print AX as unsigned number
    call crlf
    mov ax, 54321
    call PRINT_NUM       ; Print AX as signed number
    call crlf

    mov bl, var1
    add bl, var2
    add bl, var3

    mov ax, bx           ; AX contains the number for PRINT_NUM
    xor ah, ah           ; Could contain crap
    call PRINT_NUM
    call crlf

    mov ax, 4c00h
    int 21h

main endp

end main