Assembly Basics: Output register value

核能气质少年 提交于 2019-12-06 08:06:06
Sep Roland
mov ah, 00h   ; display  function here?

No, the single-char display function is at AH=2 / int 21h

Since your BL register contains only a small value (9) all it would have taken was:

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

If values become a bit bigger but not exceeding 99 you can get by with:

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

In emu8086 you can use a ready-made macro and procedure for that purpose.

Example:

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!