Skip to content

Instantly share code, notes, and snippets.

@kurtkaiser
Created April 23, 2019 01:35
Show Gist options
  • Save kurtkaiser/204b3f3b0dac5e3ec6895c81bef2568b to your computer and use it in GitHub Desktop.
Save kurtkaiser/204b3f3b0dac5e3ec6895c81bef2568b to your computer and use it in GitHub Desktop.
Basic subtraction program, MASM, written for x86 processors
; Simple Calculator
; Kurt Kaiser
INCLUDE Irvine32.inc
; .data is used for declaring and defining variables
.data
codeTitle BYTE " --------- Math Magic --------- ", 0
directions BYTE "Enter 2 numbers.", 0
prompt1 BYTE "First number: ", 0
prompt2 BYTE "Second number: ", 0
equals BYTE " = ", 0
minus BYTE " - ", 0
num1 DWORD ?
num2 DWORD ?
total DWORD ?
; .code is for the executable part of the program
.code
main PROC
; Output the title and author
mov edx, OFFSET codeTitle
call WriteString
call CrLf
; Prompt for the first number
mov edx, OFFSET prompt1
call WriteString
call ReadInt
mov num1, eax
; Prompt for the second number
mov edx, OFFSET prompt2
call WriteString
call ReadInt
mov num2, eax
; Subtract the two numbers using the eax registry
mov eax, num1
sub eax, num2
mov total, eax
; Print the total to the console
; Print num1
mov eax, num1
call WriteDec
; Print the minus sign
mov edx, OFFSET minus
call WriteString
; Print num2
mov eax, num2
call WriteDec
; Print the equals sign
mov edx, OFFSET equals
call WriteString
; Print out the total
mov eax, total
call WriteDec
call CrLf
call CrLf
exit
main ENDP
END main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment