masm师溢出 [英] masm division overflow

查看:98
本文介绍了masm师溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将两个数字相除.我正在为Irvine组装英特尔计算机书籍而工作,我无法终身从事除法工作.

I'm trying divide two numbers in assembly. I'm working out of the Irvine assembly for intel computers book and I can't make division work for the life of me.

这是我的代码

.code
main PROC
    call division
    exit
main ENDP

division PROC
    mov eax, 4
    mov ebx, 2
    div ebx
    call WriteDec
    ret
divison ENDP

END main

WriteDec应该在哪里写入eax寄存器中的任何数字(应在除法调用后设置为商).相反,每次我运行它时,Visual Studio都会崩溃(但是程序确实可以编译).

Where WriteDec should write whatever number is in the eax register (should be set to the quotient after the division call). Instead everytime I run it visual studio crashes (the program does compile however).

推荐答案

在进行除法之前,您需要将EDX寄存器归零:

You need to zero extend your EDX register before doing the division:

mov eax, 4
mov ebx, 2
xor edx, edx          ;set edx to zero
div ebx
call WriteDec

;set edx to zero是MASM中的注释.如果您在C中使用内联汇编,我不知道它是否可以工作,因此如果您使用:)

the ;set edx to zero is a comment in MASM. I don't know if it'll work if you are using inline assembly in C, so don't copy it if you are :)

这篇关于masm师溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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