汇编基础:输出寄存器值 [英] Assembly Basics: Output register value

查看:862
本文介绍了汇编基础:输出寄存器值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习汇编语言,并且已经被困在零件上以在屏幕上显示存储在寄存器中的十进制值".我正在使用emu8086,任何帮助将不胜感激! :)

I just started learning assembly language and I am already stuck on the part to "display the decimal values stored in a register on the screen". Im using the emu8086, any help would be appreciated! :)

.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

推荐答案

mov ah, 00h   ; display  function here?

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

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

由于您的BL寄存器仅包含一个小值(9),因此它只需要:

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

如果值变得更大但不超过99,则可以使用以下方法:

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

mov  al, bl       ; [0,99]
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

不使用AAM指令的解决方案:

A solution that doesn't use the AAM instruction:

mov  al, bl       ; [0,99]
cbw               ; Same result as 'mov ah, 0' in this case
mov  dl, 10
div  dl           ; Divides AX by 10: quotient in al, remainder in ah
add  ax, "00"
mov  dx, ax
mov  ah, 02h
int  21h
mov  dl, dh
int  21h

这篇关于汇编基础:输出寄存器值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆