ldr r0,array与ldr r0,=array

array是个数组,每个元素的值都是100。

S32  array[30];

array[0]=100;

如果用 ldr  r0,array  则r0的值是100。

如果用 ldr  r0,=array  则r0的值是array[0]的地址

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure, here's a sample program in ARM assembly language that sorts the 10 numbers in descending order using the bubble sort algorithm and saves them to memory starting from the address 0x00002000. The sorted numbers are also displayed in the console and LCD screen using the Embest Board Plug-In. ``` ; Define constants MEMORY_START EQU 0x00002000 NUM_ELEMENTS EQU 10 LCD_BASE_ADDRESS EQU 0x12345678 ; Replace with actual address CONSOLE_BASE_ADDRESS EQU 0x87654321 ; Replace with actual address ; Define variables array SPACE NUM_ELEMENTS * 4 temp SPACE 4 ; Main program MOV r0, #MEMORY_START ; r0 = starting address of array LDR r1, =array ; r1 = address of array LDR r2, =NUM_ELEMENTS ; r2 = number of elements in array BL bubble_sort ; Sort the array BL display_numbers ; Display the sorted numbers exit: B exit ; Infinite loop ; Bubble sort implementation bubble_sort: PUSH {r4, lr} ; Save registers MOV r3, #1 ; Boolean value to indicate when a swap has occurred outer_loop: MOV r4, #0 ; Clear the swap flag MOV r5, #1 ; r5 = index of first element inner_loop: CMP r5, r2 ; Compare r5 with number of elements BGE outer_loop ; If r5 >= number of elements, exit inner loop LDR r6, [r1, r5, LSL #2] ; r6 = array[r5] LDR r7, [r1, r5-1, LSL #2] ; r7 = array[r5-1] CMP r6, r7 ; Compare array[r5] with array[r5-1] BGE no_swap ; If array[r5] >= array[r5-1], no need to swap STR r6, [r1, r5-1, LSL #2] ; Swap array[r5] and array[r5-1] STR r7, [r1, r5, LSL #2] MOV r4, #1 ; Set the swap flag no_swap: ADD r5, r5, #1 ; Increment the index B inner_loop ; Continue inner loop CMP r4, #1 ; Check if a swap has occurred BNE outer_loop ; If no swap, the array is sorted POP {r4, pc} ; Restore registers and return ; Display the sorted numbers in console and LCD screen display_numbers: PUSH {r4, lr} ; Save registers MOV r4, #0 ; r4 = index of first element display_loop: CMP r4, r2 ; Compare r4 with number of elements BGE exit_display ; If r4 >= number of elements, exit display loop LDR r5, [r1, r4, LSL #2] ; r5 = array[r4] BL display_console ; Display the number in console BL display_lcd ; Display the number in LCD ADD r4, r4, #1 ; Increment the index B display_loop ; Continue display loop exit_display: POP {r4, pc} ; Restore registers and return ; Display a number in console display_console: ; Code to display the number in console using the CONSOLE_BASE_ADDRESS ; Replace with actual code BX lr ; Return ; Display a number in LCD screen display_lcd: ; Code to display the number in LCD using the LCD_BASE_ADDRESS ; Replace with actual code BX lr ; Return ``` Please note that this is just a sample program, and it may not work as-is in your specific environment. You may need to adjust the memory addresses and display functions based on your hardware and software setup.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值