x86组装-masm32:将变量推入堆栈的问题 [英] x86 assembly - masm32: Issues with pushing variable to stack

查看:133
本文介绍了x86组装-masm32:将变量推入堆栈的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图制作一个程序,以获取两个输入数字,然后将它们相乘(将结果存储在一个变量中),将它们相除(将结果存储在另一个变量中)并打印结果.

I'm trying to make a program that gets two input numbers, multiplies them (storing the result in a variable), divides them (storing the result in another variable) and prints the result.

我遇到的问题是代码push num1的第一行返回invalid instruction operands:

The issue I'm having is that the first line of code push num1 returns invalid instruction operands:

.data
        num1 db "Enter a number:"
        num2 db "Enter another number:"
.data?
        buffer1 dd 100 dup(?) ; this is where I store input for num1
        buffer2 dd 100 dup(?) ; " " num2
.code
start:
        push num1 ; here is where it returns the error
        call StdOut ;I want to print num1 but it doesn't get that far.
                    ; later on in my code it does multiplication and division.
        push buffer1 ; I push buffer1
        call StdIn  ; so that I can use it for StdIn
                    ; I repeat this for num2
        ; I then use those 2 numbers for multiplication and division. 

为什么会导致此错误?

Why is it causing this error?

推荐答案

start:
    push    offset num1
    call    Stdout    
    ; or 
    lea     eax, num1
    call    StdOut

    ;this:
    push    num1 
    ; is pushing the letter 'E' I believe.
    ; here is where it returns the error
    call    StdOut 

    ; this is wrong also:
    push    buffer1 ; I push buffer1 <<<  no, you are trying to push the val of buffer1
    call    StdIn  ; so that I can use it for StdIn

    ; you need to pass an address of the label (variable)
    ; so either
    lea     eax, buffer1
    push    eax
    call    StdIn

    ; or
    push    offset buffer1
    call    StdIn

这篇关于x86组装-masm32:将变量推入堆栈的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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