x86 程序集 (masm32) 输出乘数产生垃圾字符 [英] x86 assembly (masm32) output multiplied number produces junk characters

查看:23
本文介绍了x86 程序集 (masm32) 输出乘数产生垃圾字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在几个月后为了它而返回组装,但我无法将两个数字相乘并输出结果.这是我的代码:

I'm coming back to assembly for the sake of it after a few months and I'm having trouble getting two numbers to multiply and output the result. Here's my code:

.386
.model flat, stdcall 
option casemap :none 

include \masm32\include\windows.inc 
include \masm32\include\kernel32.inc 
include \masm32\include\masm32.inc 
includelib \masm32\lib\kernel32.lib 
includelib \masm32\lib\masm32.lib

.data 
     sum sdword 0
.code 
start:
mov ecx, 6        
xor eax, eax                  
mov edx, 7               
mul edx                  
push eax
pop sum
lea eax, sum
call StdOut
push 0 
call ExitProcess
end start 

它输出类似P &aeffiini,的东西.

问题:为什么它会输出那个随机字符串,我该如何解决?

QUESTION: Why does it output that random character string, and how can I fix it?

提前致谢.

推荐答案

因为 StdOut 打印 NULL 终止的字符串而不是数字.您需要先将数字转换为字符串.MASM32 具有 dwtoa.另外,你的乘法错误.你乘以 eax

Because StdOut prints NULL terminated strings NOT numbers. You need to convert the number to a string first. MASM32 has dwtoa. Also, your multiplying wrong. you multiply with eax

include masm32rt.inc

.data?
lpBuffer    db 12 dup (?)

.code 
start:
    mov     ecx, 6        
    mov     eax, 7               
    mul     eax    

    push    offset lpBuffer
    push    eax
    call    dwtoa 

    push    offset lpBuffer             
    call    StdOut

    inkey
    push    0 
    call    ExitProcess
end start 

这篇关于x86 程序集 (masm32) 输出乘数产生垃圾字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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