// In-Lab Practice - 3 // // Print out a number in decimal format // // Assume the last memory location P = x3022 // // Assume the number X = 135 // .ORIG X3000 LD R0,P ; R0 = x3022 AND R2, R2, #0 ; Clear R2 STR R2, R0, #0 ; mem[R0] = R2 LD R2,X ; R2 = 135 LD R1, ASCII ; R1 = 30 // Loop until TOP add R0, R0, #-1 ; Decrease R0 JSR DIV ; Go to DIV subroutine FOR R1 = R1x10 END_DIV ; Back from DIV ADD R4, R4, R1 ; Change to ASCII STR R4, R0, #0 ; Store the remainder to mem[R0] ADD R5, R2, #-10 ; Test R2 BRZP TOP ; Go to TOP, If R2 >= 10 // End loop // ADD R0, R0, #-1 ; Decrease R0 ADD R2, R2, R1 ; Change to ASCII STR R2, R0, #0 ; Store the remainder to mem[R0] TRAP x22 ; Print out a string from mem[R0] to mem[x3022] halt // Divider : R2 / 10 // // Input - R2 : Number // // Output - R2 : Quotient // // R3 : Remainder // DIV AND R3, R3, #0 ; Clear R3 AND R4, R4, #0 ; Clear R4 TOP_DIV ADD R5, R2, #-10 ; test BRN done_DIV ; Go to done_DIV If R2 < 10 ADD R2, R2, #-10 ; R2 = R2 - 10 ADD R3, R3, #1 ; Q = Q + 1 JSR TOP_DIV ; Go to TOP_DIV done_DIV AND R4, R2, R2 ; Store remainder to R4 AND R2, R3, R3 ; Store quotient to R2 JSR END_DIV ; Go to END_DIV P .FILL x3022 X .FILL #135 ASCII .FILL x30 .end