Danial Ahmed
Danial Ahmed

Reputation: 866

Irvine x86 Assembly Output

I am learning assembly language using Kip Irvine's Library and i was trying to create a simple program which takes two integers as input and outputs their addition and subtraction, but I am having problem outputting them.

    include irvine32.inc
.data
    myMessage BYTE "Enter First Number: ",0Ah
    myMessage1 BYTE "Enter Second Number: ",0Ah
    myMessage2 BYTE "Addition: ",0Ah
    myMessage3 BYTE "Subtraction: ",0Ah
    num1 DWORD ?
    num2 DWORD ?
.code
main proc
    mov edx, offset myMessage
    call writestring
    call readint
    mov num1, eax
    mov edx, offset myMessage1
    call writestring
    call readint
    mov num2, eax
    mov eax, num1
    add eax, num2
    mov edx, offset myMessage2
    call writeint
    mov eax, num1
    sub eax, num2
    mov edx, offset myMessage3
    call writeint
exit
main endp
end main

Expected output:

Enter First Number: 5
Enter Second Number: 3
Addition: +8
Subtraction: +2

but I am getting

OUTPUT SS

Upvotes: 1

Views: 2166

Answers (1)

Tommylee2k
Tommylee2k

Reputation: 2731

I don't know irvine, but the manual is pretty much clear

This is probably what you wanted

    include irvine32.inc
.data
; the strings have to be terminated, so ",0" is added:
    myMessage BYTE "Enter First Number: ",0      
    myMessage1 BYTE "Enter Second Number: ",0
    myMessage2 BYTE "Addition: ",0
    myMessage3 BYTE "Subtraction: ",0
    myMessage3 BYTE 10,13,0
    num1 DWORD ?
    num2 DWORD ?
.code
main proc
    mov edx, offset myMessage
    call writestring
    call readint
    mov num1, eax
    mov edx, offset myMessage1
    call writestring
    call readint
    mov num2, eax

    ; addition, compose the line ( 3 parts: prompt, number, newline)
    mov edx, offset myMessage2
    call writestring
    mov eax, num1
    add eax, num2
    call writeint
    mov edx, offset newLine    ; add a CrLF here
    call writestring


    ; subtraction
    mov edx, offset myMessage3
    call writestring
    mov eax, num1
    sub eax, num2
    call writeint
    mov edx, offset newLine
    call writestring

exit
main endp
end main

Upvotes: 1

Related Questions