Created
April 23, 2019 01:14
-
-
Save kurtkaiser/a38a011de74df71e1a985ddbf2ad78da to your computer and use it in GitHub Desktop.
A simple addition program written in MASM, Assembly for x86 processors.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Simple Calculator | |
; Kurt Kaiser | |
INCLUDE Irvine32.inc | |
; .data is used for declaring and defining variables | |
.data | |
num1 DWORD ? | |
num2 DWORD ? | |
codeTitle BYTE " --------- Math Magic --------- ", 0 | |
directions BYTE "Enter 2 numbers.", 0 | |
prompt1 BYTE "First number: ", 0 | |
prompt2 BYTE "Second number: ", 0 | |
equals BYTE " = ", 0 | |
plus BYTE " + ", 0 | |
total DWORD ? | |
; .code is for the executable part of the program | |
.code | |
main PROC | |
; Output tode 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 | |
; Add the two numbers using the eax registry | |
mov eax, num1 | |
add eax, num2 | |
mov total, eax | |
; Print the total to the console | |
; Print num1 | |
mov eax, num1 | |
call WriteDec | |
; Print the plus sign | |
mov edx, OFFSET plus | |
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