Skip to content

Instantly share code, notes, and snippets.

@mjdargen
Last active July 7, 2021 19:56
Show Gist options
  • Save mjdargen/be3815bf6a1c6ac6d326efbfe0a7afdd to your computer and use it in GitHub Desktop.
Save mjdargen/be3815bf6a1c6ac6d326efbfe0a7afdd to your computer and use it in GitHub Desktop.
Starting point for HW8 Question #2.
;
; temp.asm - converts between celsius and fahrenheit
; Description - start code for HW8
;
.ORIG x3000
LD R1, TEMP ; load temperature
LD R2, UNIT ; load whether celsius/fahrenheit
BRz CELS ; if zero, interpret as C convert to F
JSR F2C ; call fahrenheit to celsius conversion subroutine
BRnzp END ; unconditionally branch to end
CELS JSR C2F ; call celsius to fahrenheit conversion subroutine
END ST R1, OUTPUT ; store output temperature
HALT
; -------------------- CELS to FAHR CONVERSION SUBROUTINE -------------------- ;
; Description: converts temperature in celsius to fahrenheit
; Inputs: R1 - temp in celsius
; Outputs: R1 - temp in fahrenheit
C2F RET
; -------------------- FAHR to CELS CONVERSION SUBROUTINE -------------------- ;
; Description: converts temperature in fahrenheit to celsius
; Inputs: R1 - temp in fahrenheit
; Outputs: R1 - temp in celsius
F2C RET
; ----------------------- RAW VALUES STORED IN MEMORY ------------------------ ;
TEMP .FILL x0017 ; temperature value decimal 23
UNIT .FILL x0001 ; units: 0 for celsius, 1 for fahrenheit
OUTPUT .BLKW 1 ; placeholder for output temperature
.END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment