这是code正确(编号+数字,然后打印出结果) [英] Is this code correct (Number plus number, then print the result)
问题描述
我想要做的事汇编语言简单。结果
另外两个数字,并在屏幕上打印的结果。
I want to do something simple in assembly language.
addition two numbers, and print the result on the screen.
我这样做,code:
.Model SMALL
.Stack 100h
.Code
start:
MOV ax, 10
ADD ax, 5
MOV ah, 02h
INT 21h
MOV ah, 01h
INT 21h
MOV ah, 4ch
INT 21h
end start
编译后,code没有任何错误,告诉我一个奇怪的字符。
After compile the code without any error, tells me a strange character .
修改
MOV dl, 10
ADD al,5
MOV dl, al
MOV ah,02h
INT 21h
但仍然打印一个性格怪异
我不知道我能做些什么来打印屏幕上的数字
but still print a strange character I don't know what can I do to print number on the screen
推荐答案
是的,你的将会的最有可能得到一个奇怪的字符,因为INT 21 / AH = 02,需要的字符打印到在该 DL
注册,并且您还没有填充 DL
与任何东西。
Yes, you will most likely get a strange character because int 21/ah=02 requires the character to print to be in the dl
register, and you haven't populated dl
with anything.
您可能要价值的东西,如转移:
You may want to transfer the value with something like:
mov ax, 10
add ax, 5
push ax ; these are the two new lines.
pop dx
mov ah, 02h
但是,请记住,即使你的不的从人
的价值转移到 DL
,人物15号可能不是你所期望的。 15是ASCII控制字符中的一个,我不知道什么是DOS中断将输出他们。
However, keep in mind that, even if you do transfer the value from al
to dl
, character number 15 may not be what you expect. 15 is one of the ASCII control characters and I'm not sure what the DOS interrupts will output for them.
如果您想打印出来的数字 15
,你需要的两个的电话,其中一个 DL = 31H
,第二个具有 DL = 35H
(两个ASCII codeS为 1
和 5
字符)。
If you want to print out the digits15
, you will need two calls, one with dl = 31h
and the second with dl = 35h
(the two ASCII codes for the 1
and 5
characters).
如果你想知道如何采取了一些在寄存器和输出的数字的为可读的形式,这个数字,有一个在<一个伪一些code href=\"http://stackoverflow.com/questions/7884143/how-to-print-numbers-greater-then-10-in-arm200-assembly-language/7884259#7884259\">an刚才的答复矿的。
If you want to know how to take a number in a register and output the digits for that number in readable form, there's some pseudo-code in an earlier answer of mine.
从这个问题的答案,你有伪code:
From that answer, you have the pseudo-code:
val = 247
units = val
tens = 0
hundreds = 0
loop1:
if units < 100 goto loop2
units = units - 100
hundreds = hundreds + 1
goto loop1
loop2:
if units < 10 goto done
units = units - 10
tens = tens + 1
goto loop2
done:
if hundreds > 0: # Don't print leading zeroes.
output hundreds
if hundreds > 0 or tens > 0:
output tens
output units
;; hundreds = 2, tens = 4, units = 7.
现在你需要翻译成x86汇编。让我们开始在斧
所需的值:
Now you need to translate that into x86 assembly. Let's start with the desired value in ax
:
mov ax, 247 ; or whatever (must be < 1000)
push ax ; save it
push dx ; save dx since we use it
mov dx, 0 ; count of hundreds
loop1:
cmp ax, 100 ; loop until no more hundreds
jl fin1a
inc dx
sub ax, 100
jmp loop1
fin1a:
add dx, 30h ; convert to character in dl
push ax ; save
mov ah, 2
int 21h ; print character
pop ax ; restore value
; now do tens and units the same way.
pop dx ; restore registers
pop ax
现在,code段(尽管由于这一事实,任何错误它已经,因为我做了一个组装时)应打印出百位,并留下斧只有几十个位数。
Now that code segment (notwithstanding any errors due to the fact it's been a while since I did assembly) should print out the hundreds digit and leave ax with only the tens and units digit.
这应该是一个简单的事情重复的功能两次拿到几十家单位和场所。
It should be a simple matter to duplicate the functionality twice more to get the tens and units places.
这篇关于这是code正确(编号+数字,然后打印出结果)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!