Skip to content

Instantly share code, notes, and snippets.

@davidcalhoun
Created June 23, 2011 12:37
Show Gist options
  • Save davidcalhoun/1042459 to your computer and use it in GitHub Desktop.
Save davidcalhoun/1042459 to your computer and use it in GitHub Desktop.
Old assembly code from class
// found this in my Gmail drafts... old assemly code from when I was taking this class in 2008 or so?
.ORIG x3000    ;program start
IN        ;read character from keyboard
ADD R2, R0, #0    ;place the character into R2
IN       
ADD R3, R0, #0    ;define R3
IN
ADD R4, R0, #0    ;define R4
ADD R5, R2, #0    ;R5 = R2
NOT R6, R3    ;R6 is temp
ADD R6, R6, #1    ;R6 = -R3
ADD R7, R6, R5    ;R7 = R5 - R3
BRzp LABEL1    ;if R5 >= R3, go to LABEL1
ADD R5, R3, #0    ;R5 < R3, so redefine R5 to be R3
LABEL1 NOT R6, R4
ADD R6, R6, #1    ;-R4
ADD R7, R6, R5
BRzp LABEL2    ;if R5 >= R4, go to LABEL2
ADD R5, R4, #0    ;R5 < R4, so redefine R5 to be R4
LABEL2 ADD R0, R5, #0    ;R0 holds the largest ASCII
OUT
HALT
.END
----------------------
.ORIG x3000            ;program start
ADD R2, R2, #5            ;R2 is a counter
ADD R3, R3, #0            ;R3 is the total
STARTLOOP ADD R3, R3, R2    ;R3 += R2
ADD R2, R2, #-1            ;R2 -= R2 (decrement counter)
BRp STARTLOOP            ;if R2 > 0
LOOPDONE ADD R0, R3, #0        ;
OUT                ;output result
HALT
.END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment