assembly 基础 : Output register value

标签 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

最佳答案

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       ; [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 指令的解决方案:
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

关于 assembly 基础 : Output register value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34254461/

相关文章:

c++ - 为什么 vs c++ 2010 编译器会为相似的函数生成不同的汇编代码

command-line - DEL 说路径不存在(它确实存在)

shell - 可以将命令别名自动添加到DOS shell中吗?

assembly - 为什么在将 Int 0x21 与服务 0x2c 一起使用时,可编程间隔计时器不显示正确的时间值

assembly - x86实模式调用不保存返回地址

arrays - 如何索引汇编中的字符串

linux - 汇编浮点运算

assembly - 如何在 NASM 中推送 64 位整数?

ftp - 如果我使用 DOS put 命令来 ftp 文件,它是否会覆盖现有文件、附加到该文件或导致错误?

assembly - 加载引导加载程序的第二阶段并启动它