+/EE306
intro to computing
git clone https://git.julia.blue/+/EE306
7702458
master
1; Computes f(R0), storing the result in R4 2.ORIG x5000 3ST R1 , saver1 4ST R2 , saver2 5ST R3 , saver3 6ST R5 , saver5 7ST R6 , saver6 8ST R7 , retaddr 9LD R6 , poly 10LDR R5 , R6 , #0 ; R5 = Degree 11ADD R6 , R6 , #1 12LDR R1 , R6 , #0 ; R1(output) = first term 13loop2 ADD R5 , R5 , #-1 ; Degree -= 1 14BRn done ; If degree <= 0: end loop 15JSR mult ; Output *= X 16AND R1 , R2 , R2 17ADD R6 , R6 , #1 18LDR R2 , R6 , #0 19ADD R1 , R1 , R2 ; Add next term to output 20BR loop2 21done AND R4 , R1 , R1 22LD R1 , saver1 23LD R2 , saver2 24LD R3 , saver3 25LD R5 , saver5 26LD R6 , saver6 27LD R7 , retaddr 28RET 29poly .FILL x4003 30saver1 .BLKW #1 31saver2 .BLKW #1 32saver3 .BLKW #1 33saver5 .BLKW #1 34saver6 .BLKW #1 35retaddr .BLKW #1 36 37; Multiplies R0 and R1 (in constant rather than linear time), placing the 38; result in R2 (clobbers R1-R4) 39mult AND R4 , R4 , #0 ; Set negative flag to false 40ST R7 , saver7 41ST R0 , saver0 42AND R0 , R0 , R0 43BRzp posA ; If R0 is negative: set it to it's absolute value 44NOT R0 , R0 ; and flip the negative flag 45ADD R0 , R0 , #1 46NOT R4 , R4 47posA AND R1 , R1 , R1 48BRzp posB ; Do the same for R1 49NOT R1 , R1 50ADD R1 , R1 , #1 51NOT R4 , R4 52posB AND R3 , R3 , #0 53ADD R3 , R3 #1 ; Set the mask to 1 54AND R2 , R2 , #0 ; Clear the output 55loop AND R7 , R0 , R3 56BRz skip 57ADD R2 , R2 , R1 ; If R0[mask] == 1: add R1 to output 58skip ADD R1 , R1 , R1 ; Bitshift the mask and R1 left by one 59ADD R3 , R3 , R3 60BRnp loop ; Repeat for each bit 61AND R4 , R4 , R4 62BRz pos ; If the flag is enabled, negate the output 63NOT R2 , R2 64ADD R2 , R2 , #1 65pos LD R0 , saver0 66LD R7 , saver7 67RET 68saver0 .BLKW #1 69saver7 .BLKW #1 70 .END