diegoaguilar
diegoaguilar

Reputation: 8376

What's could it be wrong in this Linux Assembler Code?

I need to make a simple 4 functions calculator for 2 numbers coding with Linux Assembler, however the programm works not fully ok because sometimes fails on reading the 2 numbers.

My setup and data:

bits 32
global main

extern scanf
extern printf
extern exit

section .data
    menu:   db ; truncated, but essentially a string            
    msg1:   db "El resultado de la suma es: %d", 10, 0
    msg2:   db "El resultado de la resta es: %d", 10, 0
    msg3:   db "El resultado de la multiplicacion es: %d", 10, 0
    msg4:   db "El resultado de la division es: %d", 10, 0
    in1:    db "Proporciona dato 1: ", 10
    in2:    db "Proporciona dato 2: ", 10   
    fmt:    db "%d"
    x:      dd 0
    y:      dd 0

The function I believe isn't always working:

leer:
    push dword in1
    call printf
    add esp, 4

    push dword x
    push dword fmt
    call scanf
    add esp, 8

    push dword in2
    call printf
    add esp, 4

    push dword y
    push dword fmt
    call scanf
    add esp, 8
    ret

The original code can be found here: http://notepad.cc/piloobru13

Upvotes: 2

Views: 165

Answers (1)

Bo Persson
Bo Persson

Reputation: 92381

Some of your strings are not zero terminated.

That will likely confuse printf and scanf.

Upvotes: 2

Related Questions