Skip to content

Instantly share code, notes, and snippets.

@JoshTGreenwood
Created September 15, 2014 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshTGreenwood/5a4eefa13037a821c2e3 to your computer and use it in GitHub Desktop.
Save JoshTGreenwood/5a4eefa13037a821c2e3 to your computer and use it in GitHub Desktop.
Microcomputer Design Lab 1
OPT MEX expand macro calling
OPT SEX expand structured statements
CODE EQU 0 define code and text sections
TEXT EQU 1
CR EQU $0D define CR and LF
LF EQU $0A
SECTION TEXT
ORG $800 sets the address for text code
SECTION CODE
ORG $2000 sets the address for program code
print MACRO
lea \1,a1 sets address a1 to the address of the input
move.b #14,d0 sets d0 with ouput function
trap #15 calls d0 which contains output function
ENDM
getInput MACRO
move.b #4,d0 sets d0 with input function
trap #15 calls d0 which contains input function
ENDM
addFunc MACRO defines addFunc macro
print numberPrompt prints numberPrompt
getInput gets input from user
move.l d1,d2 moves input to d2
print numberPrompt prints numberPrompt
getInput gets input from user
add.l d2,d1 adds d2 to d1
results calls results macro
ENDM
subFunc MACRO
print numberPrompt prints numberPrompt
getInput gets input from user
move.l d1,d2 moves input to d2
print numberPrompt prints numberPrompt
getInput gets input from user
sub.l d1,d2 subtracts d1 from d2
move.l d2,d1 moves d2 to d1
results calls results macro
ENDM
results MACRO
print resultMsg prints resultMsg
move.b #3,d0 sets d0 with function to display integer
trap #15 calls d0 to display integer
ENDM
terminate MACRO
STOP #2000 ends program excecution
PRINT goodbyeMsg prints goodbyeMsg
ENDM
ORG $1000 defines below for $1000
START: start of excecution
PRINT welcomeMsg prints welcomeMsg
repeat loops
PRINT instructionMsg prints instructionMsg
getInput calls getInput macro
if d1 <eq> #1 then if input is 1, call addFunc macro
addFunc
else
if d1 <eq> #2 then if input is 2, call subFunc macro
subFunc
endi
endi
until d1 <eq> #3 do if input is 3, call terminate macro
terminate
SECTION text defines each message
welcomeMsg dc.b CR,LF,'Welcome to Calculator.',CR,LF,0
instructionMsg dc.b CR,LF,'Please enter 1 for addition, 2 for subtraction, or 3 to exit:',0
numberPrompt dc.b CR,LF,'Please enter a number: ',0
resultMsg dc.b CR,LF,'Result: ',0
goodbyeMsg dc.b CR,LF,'Goodbye!!',0
END start end of excecution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment