1

So i am making a calculator in assembly like i would in c or c++ or any other language but the output is being really weird it is printing all of them out then taking input

NOTE: THIS IS IN x86_64 ASM THAT IS WHY I AM USING 64 BIT REGISTERS FOR THE ARGS
NOTE: THIS IS NOT CLOSE TO DONE I AM JUST WORKING ON TAKING INPUT
main.asm

section .data
    p1 db "Enter first number: "
    p2 db "Enter seccond number: "
    p3 db "Enter operation", 0xa, "1)Add", 0xa, "2)Subtract",0xa, "3)Multiply",0xa, "4)Divide", 0xa, "> "
    p1len equ $-p1
    p2len equ $-p2
    p3len equ $-p3
section .bss
    n1 resb 8
    n2 resb 8
    op resb 8
section .text
    global _start
_start:
    call _doN1
    call _doN2
    call _doOps
    mov rax, 60
    mov rdi, 0
    syscall
_doOps:
    mov rax, 1
    mov rdi, 1
    mov rsi, p3
    mov rdx, p3len
    syscall
    mov rax, 0
    mov rdi, 0
    mov rsi, op
    mov rdx, 8
    syscall
    ret
_doN1:
    mov rax, 1
    mov rdi, 1
    mov rsi, p1
    mov rdx, p1len
    syscall
    mov rax, 0
    mov rdi, 0
    mov rsi, n1
    mov rdx, 8
    syscall
    ret
_doN2:
    mov rax, 1
    mov rdi, 1
    mov rsi, p2
    mov rdx, p2len
    syscall
    mov rax, 0
    mov rdi, 0
    mov rsi, n2
    mov rdx, 8
    syscall
    ret
Output: 
Enter first number: Enter seccond number: Enter operation
1)Add
2)Subtract
3)Multiply
4)Divide
> 3
Enter seccond number: Enter operation
1)Add
2)Subtract
3)Multiply
4)Divide
> 6
Enter operation
1)Add
2)Subtract
3)Multiply
4)Divide
> 1
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
koukah
  • 69
  • 1
  • 6
  • You need to put the length definitions right after the thing whose length you define. – fuz Nov 24 '20 at 23:15
  • @fuz thank you im sorry for the stupid mistake :) – koukah Nov 24 '20 at 23:26
  • 1
    @fuz: There's a canonical duplicate for this ([In NASM labels next to each other in memory are causing printing issues](https://stackoverflow.com/q/26897633)), linked from [How does $ work in NASM, exactly?](https://stackoverflow.com/q/47494744). No need to close this as "typo or trivial / not reproducible". – Peter Cordes Nov 25 '20 at 01:21
  • @PeterCordes Thanks. I completely forgot about that duplicate. – fuz Nov 25 '20 at 11:04

0 Answers0