Programming

# Programming - Loop/Iteration 0011 0000 0000 0000 0101 010...

This preview shows pages 1–3. Sign up to view the full content.

Loop/Iteration 0011 0000 0000 0000 ;start program at 3000 0101 010 010 1 00000 ;set R2=0 (counter) 0101 011 011 1 00000 ;set R3=0 (sum) 0001 010 010 1 00100 ;set R2=4 (counter) 0000 010 000000011 ;cond. branch, if 0, store in ;mem(x4030) 0001 011 011 0 00 001 ;R3=R3+R1 0001 010 010 1 11111 ;decrement R2 0000 111 111111100 ;uncond. branch, 0001 110 110 1 01111 ;add 15 to R6 0001 110 110 1 00010 ;add 2 to R6 0111 011 110 011111 ;STR R3 into mem(x4030) via R6 1111 0000 00100101 ;halt Multiply ; Program to multiply a number by the constant 6 ; .ORIG 0x3050 LD R1, SIX LD R2, NUMBER AND R3, R3, #0 ; Clear R3. It will ; contain the product. ; The inner loop ; AGAIN ADD R3, R3, R2 ADD R1, R1, #-1 ; R1 keeps track of BRp AGAIN ; the iteration. ; HALT ; NUMBER .BLKW 1 #67 ; # to be multiplied SIX .FILL 0x0006 ; .END Using TRAP Instruction ;This program converts typed capital letter to lowercase ; .ORIG x3000 LD R2, TERM ; Load negative ASCII ‘7’ LD R3, ASCII ; Load ASCII difference ; AGAIN TRAP x23 ; input character ADD R1, R2, R0 ; Test for terminate BRz EXIT ; Exit if done ADD R0, R0, R3 ; Change to lowercase TRAP x21 ; Output to monitor. .. BRnzp AGAIN ; ... again and again. .. ; EXIT TRAP x25 ; halt ; TERM .FILL xFFC9 ; -‘7’ ASCII .FILL x0020 ; lowercase bit ; .END

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Squares a positive integer N by adding a to itself (N – 1) times ; ; Squares the value in R0 (a positive 2C integer) ; Returns result to R0 ; Also uses GPRs R2, R3 (without save/restore) ; SQUARE ADD R2, R0, #0 ; counter n ADD R3, R0, #0 ; tmp n AGAIN ADD R2, R2, #-1 ; decrement counter BRz DONE ADD R0, R0, R3 ; accumulate BRnzp AGAIN DONE RET ; R0 = n 2 Using SQRT Subroutine .ORIG 0x3000 .EXTERNAL SQRT ... LD
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

Programming - Loop/Iteration 0011 0000 0000 0000 0101 010...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online