使用以下代码作为程序的开头。写一个程序找出最大和最小的数。最大和最小的数字需要分别保存在寄存器r7和r8中。对于ARMSim#,这些数字也需要显示在控制台和LCD屏幕上(使用Embest Board) 代入量) MOV r0, #0x00002000 MOV r1, #9 STR r1, [r0],#4 MOV r1, #3 STR r1, [r0],#4 MOV r1, #1 STR r1, [r0],#4 MOV r1, #4 STR r1, [r0],#4 MOV r1, #8 STR r1, [r0],#4 MOV r1, #5 STR r1, [r0],#4 MOV r1, #7 STR r1, [r0],#4 MOV r1, #2 STR r1, [r0],#4 MOV r1, #10 STR r1, [r0],#4 MOV r1, #6 STR r1, [r0],#4,注释用英文
时间: 2023-07-02 07:10:06 浏览: 92
```
; Initialize registers
MOV r7, #0 ; Initialize register r7 to 0
MOV r8, #0xFFFFFFFF ; Initialize register r8 to the maximum possible value
; Load array into memory
MOV r0, #0x00002000 ; Address of the array
MOV r1, #9 ; Number of elements in the array
STR r1, [r0],#4 ; Store element 9 at address r0, increment r0 by 4 bytes
MOV r1, #3
STR r1, [r0],#4
MOV r1, #1
STR r1, [r0],#4
MOV r1, #4
STR r1, [r0],#4
MOV r1, #8
STR r1, [r0],#4
MOV r1, #5
STR r1, [r0],#4
MOV r1, #7
STR r1, [r0],#4
MOV r1, #2
STR r1, [r0],#4
MOV r1, #10
STR r1, [r0],#4
MOV r1, #6
STR r1, [r0],#4
; Find the maximum and minimum values
MOV r1, #0x00002000 ; Start of the array
MOV r2, #0 ; Counter
loop:
LDR r3, [r1], #4 ; Load the next element
CMP r3, r8 ; Compare with current maximum value
BLE endloop ; If less than or equal to, go to endloop
MOV r8, r3 ; Set new maximum value
endloop:
CMP r2, #8 ; Check if we've gone through all elements
BEQ done ; If so, we're done
ADD r2, r2, #1 ; Increment the counter
B loop ; Go back to loop
done:
MOV r1, #0x00002000 ; Start of the array
MOV r2, #0 ; Counter
loop2:
LDR r3, [r1], #4 ; Load the next element
CMP r3, r7 ; Compare with current minimum value
BGE endloop2 ; If greater than or equal to, go to endloop2
MOV r7, r3 ; Set new minimum value
endloop2:
CMP r2, #8 ; Check if we've gone through all elements
BEQ done2 ; If so, we're done
ADD r2, r2, #1 ; Increment the counter
B loop2 ; Go back to loop2
done2:
; Display the maximum and minimum values
; For ARMSim#, you'll need to use the appropriate system calls to display the values on the console and LCD screen
```
阅读全文