在汇编中显示两位数字? [英] Displaying two digit numbers in assembly?

查看:324
本文介绍了在汇编中显示两位数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是汇编程序设计的新手.在课堂上的示例中,要求将两个数字相加并显示总和,而我发现有些隐晦的地方是在显示两位数时显示总和. 这是我的代码.

I am completely new to assembly programming. In of the examples at classwork its required to add two numbers and display the sum, what I find cryptic is display the sum when its a two digit number. Here's my code.

    mov al,num1
    mov bl,num2

    add al,bl

    add ax,3030h

    mov dl,ah
    mov ah,02h
    int 21h

    mov dl,al
    mov ah,02h
    int 21h

    mov ah,4ch
    int 21h

虽然加法可能会导致一个打包的数字,但我如何解压缩它并显示为两个不同的十进制数字?

While the addition might result in a packed number, how do I unpack it and display as two different numbers in decimal?

推荐答案

我也是汇编的新手. 但是我认为这会对您有所帮助.

I'm also new to assembly. But I think this will help you.

 
.model small
.stack 100h
.data 
    msg1 db "Enter number 1:$"
    msg2 db "Enter number 2:$"
    msg3 db "Sum is:$"
    no1 db 0
    no2 db 0
    mysum db 0
    rem db 0


.code 
    mov ax,@data 
    mov ds,ax

;print msg 1
    mov dx,offset msg1 
    mov ah,09h
    int 21h

;read input no1
    mov ah,01h
    int 21h
    sub al,48
    mov no1,al

;print new line
    mov dl,10
    mov ah,02h
    int 21h

;print msg2
    mov dx,offset msg2
    mov ah,09h
    int 21h

;read input 2
    mov ah,01h
    int 21h
    sub al,48
    mov no2,al

;print new line 
    mov dl,10
    mov ah,02h
    int 21h

;print msg3
    mov dx,offset msg3
    mov ah,09h
    int 21h

;add two numbers
    mov dl,no1
    add dl,no2
    ;moving the sum to mysum
    mov mysum,dl

    ;clear AH to use for reminder
    mov ah,00
    ;moving sum to al
    mov al,mysum
    ;take bl=10
    mov bl,10
    ;al/bl --> twodigit number/10 = decemel value
    div bl
    ;move reminder to rim
    mov rem,ah
    ;to print (al) we move al to dl
    mov dl,al
    add dl,48
    mov ah,02h
    int 21h

    ;to print the reminder
    mov dl,rem
    add dl,48
    mov ah,02h
    int 21h

    mov ax,4c00h
    int 21h
end

在这里,我要做的是将总数取走,并将其移至可以保留的总数上. 然后我将其除以10并打印商和提醒. 如果您觉得有问题.你可以问.谢谢 !

here what I've done is I took the total and move it to al that can keep it. then I divide it by 10 and print the quotient and reminder. If you feel problem. you can ask. Thank you !

这篇关于在汇编中显示两位数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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