程序代写代做代考 ; input: starting in address 80 and ends with number 00
; input: starting in address 80 and ends with number 00
; tested input: 10, 20, 30, 50, 60, 40
; output: same with input location, but with data reversed.
; load constants
load R0, 0
load R1,1
load R2,-1
load R3, 80 ; R3 stores the beginning address of the data
; find the last position of the input data
move R4,R3
FindLast:
load R6,[R4]
jmpEQ R6=R0,Jout ;; the data is 0 which indicates the end of input data
addi R4,R4,R1
jmp FindLast
Jout:
addi R4,R4,R2 ;; now R4 stores the last position of the input data
Reverse:
move R0,R3
jmpLE R4<=R0,Exit ;; test whether reverse finishes
;; load the start and end number of current range
load R6,[R3]
load R7,[R4]
;; swap the two numbers
store R7,[R3]
store R6,[R4]
;; update beginning and ending address
addi R3,R3,R1
addi R4,R4,R2
;; continue to reverse in the new range
jmp Reverse
Exit:
halt ;; end the program
;; input data stored in address beginning in 80
org 80
Input: db 10, 20, 30, 50, 60, 40, 0
/docProps/thumbnail.jpeg