Job 1
Area exone, code, readwriteentry code32 mov r0, #100; number of times mov R1, #1 to be compared in the Register; initial two numbers mov R2, #0 loop add R2, r2, R1; add R1, R1, #1 in pairs; automatically add sub r0, R0, #1; subtract one CMP R0 from the number to be added, #0; determine whether the number of comparisons is zero BNE loop LDR R3, = resultstr R2, [R3] resultdcd 0 stopb stop
Assignment 2
Area extwo, code, readwrite entrycode32; sort: Bubble sorts the data at the target address, from small to large movs R2, #1; r2 = sorting completion mark, 1 indicates incomplete againldr r0, = data; R0 = destination data block address mov R1, #40; r2 = number of sorted words subs R1, R1, #4 ands R2, R2, #1; Determine whether the sorting is complete beq stop; If r2 = 0, complete movs R2, #0; otherwise, the flag is set to 0; When fd sp !, {R4}; Save the working register judge LDR R3, [R0]; read the value obtained from the R0 address to r3ldr R4, [r0, #4]; read the R0 address and get the value to r4cmp R3 and R4. Compare the sizes of r4cmp and r4cmp to next. If R3 <= R4, it jumps to nextexchangemovs R2, #1. Data exchange occurs, set the flag to 1str R3, [r0, #4]; exchange the values of STR R4, [R0] Next adds r0, R0, #4; add 4 Subs R1 to the target address, r1, #4; The Count value is reduced by 1bne judge; This sorting is not completed, and it is jumped to judge_2b again; otherwise, the next ldmfd SP !, {R4}; resume the working register; Forward control of the program to the debugger stopdata DCD 9, 4, 6, 7, 8, 1, 3, 2, stop B stop
Assignment 3
; Add. s assembler stack_top equ 0x40002000preserve8export addarea add, code, readonlyimport sumexport startentrystartldr R13, = stack_top mov r0, # 1mov R1, # 100bl sumldr R5, = resultstr r0, [R5] resultdcd 0end // sum. C program int sum (int A, int B) {int sum = 0, I; for (I = A; I <= B; I ++) sum + = I; return sum;}; add1.s assembler stack_top equ 0x40002000preserve8area sum, code, readonlyexport add1import mainexport startstart LDR R13, = stack_topb main Entryadd1 add R2, R2, R0; add r0, R0, #1 in pairs; automatically add sub R1, R1, #1; subtract one CMP R1 from the number to be added, #0; determine whether the number of comparisons is zero BNE add1mov PC, lrend // sum1.c # include <stdio. h> extern int Add1 (int A, int B, int C); int main () {int A = 0; printf ("sum 1 to 100 :"); A = Add1 (1,100, 0); printf ("% d", a); return 1 ;}; strcopy. sstack_top equ 0x40002000preserve8area scopy, code, readonlyexport strcopyimport mainexport startstart LDR R13, = stack_topb mainentrystrc Opyldrb R2, [R1], #1 strb R2, [R0], # 1cmp R2, # 0bne strcopymov PC, lrend // main. C program # include <stdio. h> extern void strcopy (char * D, const char * s); int main () {const char * srcstr = "abcdefghij"; char detstr [] = "second string "; printf ("before copying: \ n"); strcopy (detstr, srcstr); printf ("after copying: \ n "); printf ("% s \ n", srcstr, detstr); return 1 ;}; strcopy. sstack_top equ 0x40002000preserve8export copyarea copy, cod E, readonlyimport copystrexport startentrystart LDR R13, = stack_topldr r0, = srcldr R1, = dstbl copystrsrc DCB "abcdefghij" dstdcb "helloworld" End // copystr. C program # include <stdio. h> void copystr (char * D, char * s) {While (* D ++ = * s ++ )! = '\ 0 ');}
Assignment 4
1. Area myarea, code entry mov r0, #9 mov R1, #15 startcmp r0, r1bne judgebeq stopsub1sub r0, R0, r1sub2sub R1, R1, r0judgecmp r0, r1bgt sub1blt sub2stopb stopend2, arry_size equ 10 Area text, code entrystartmov R2, # 10ldr r0, = 1_r3, [R0] B addnextsaveldr R4, = resultb stopaddnextldr R1, [R0, #4]! Add R3, R1, r3sub R2, R2, # 1cmp R2, # 0beq savebne addnextarry_datadcd, 9, 0 space limit 0 stopb stopend3, stack_top equ 0x40001000area myex, codeentrymov r0, # 0mov R1, # 1mov R2, # 2mov R3, # 3mov R4, # 4mov R5, # 5mov R6, # 6ldr R13, = stack_top1_fd R13 !, {R0-R6}; decrease beforehand, save ldmfd R13 !, {R3, R4, R6}; restores the field ldmfd R13 in ascending mode !, {R5} ldmfd R13 !, {R0, R1, R2} datadcd 1, 2, 3 stopb stop4, area test4, code entrystartldr R5, = dataldr r0, [R5] mov R1, # 0x000000ffmov R2, # 0x0000ff00mov R3, # 0x00ff0000mov R4, #0xff000000; add and R1, r0lsl R1, # 24ldr r0, [R5] and R2, r0lsl R2, # 8ldr r0, [R5] and R3, r0lsr R3, # 8ldr r0, [R5] and R4, r0lsr R4, # 24add R1, R1, r2add R3, R3, r4add r0, R1, r3b stopdatadcd 0 xaabbccddstopb stopend