Question: this is what i got so far need help @Matthew Fundora @Professor @ @ .equ SWI_Open, 0x66 @open file .equ SWI_Close,0x68 @close a file .equ
this is what i got so far need help
@Matthew Fundora @Professor @ @
.equ SWI_Open, 0x66 @open file .equ SWI_Close,0x68 @close a file .equ SWI_PrStr,0x69 @write a null ending string .equ SWI_RdInt,0x6c @read an int .equ SWI_PrInt,0x6b @print an int .equ Stdout, 1 @set output target to stdout .equ SWI_Exit,0x11 @exit .global _start .text
_start: @=================open a file for reading=========================== mov R0, #Stdout ldr R1, =Message @load address of message swi SWI_PrStr
ldr r0,=InFileName @set name for output file mov r1,#0 @mode is input swi SWI_Open @open file bcs InFileError
ldr r9,=InputFileHandle @set input file handle and store it str r0, [r9] ldr r0,[r9] @load input file handle swi SWI_RdInt mov r8, r0 @move r0 first int to r8
str r8, [r8] @store it mov r5, #1 @r5 accumulates total @=========================read integers until end of file================= RLoop: ldr r0,[r9] swi SWI_RdInt @read integer into r0 bcs EofOneReached @check if end reached
ADD r5, r5, #1 @add 1 to r5 and store in r5, counter CMP r5, r8 @Compare counter to (i) int movEQ r6, r0 @if true then mov r0 to r6
bal RLoop @keep reading until end of file @ ====== End of File==================================================
EofOneReached: ldr R0, =InputFileHandle ldr R0, [R0] swi SWI_Close mov r4, mov r10, ldr r0,=InFileName @set name for output file mov r1,#0 @mode is input swi SWI_Open bcs InFileError str r0, [r9] @========second loop================================================== Loop:
ldr r0,[r9] swi SWI_RdInt @read integer into r0 bcs EofReached @check if end reached CMP r0, r6 @compare r0 to r6 ADDLT r4, r4, #1 @if r0 is less than j, add 1 to r4
TST R0, #1 @test if R0 is odd ADD r3, r3, #1 @if yes then add r3 to 1 and store in r3
bal Loop @======final printout================================================= EofReached:
SUB r10, r3, r4 @r10 = r4-r3, get evens less than j
mov r0, #Stdout ldr r1, =INum swi SWI_PrStr mov r1, r8 swi SWI_PrInt ldr r1, =NL swi SWI_PrStr
mov r0, #Stdout ldr r1, =JNum swi SWI_PrStr mov r1, r6 swi SWI_PrInt ldr r1, =NL swi SWI_PrStr
mov r0, #Stdout ldr r1, =TotInt swi SWI_PrStr mov r1, r5 swi SWI_PrInt ldr r1, =NL swi SWI_PrStr
mov r0, #Stdout ldr r1, =IntLesJ swi SWI_PrStr mov r1, r4 swi SWI_PrInt ldr r1, =NL swi SWI_PrStr
mov r0, #Stdout ldr r1, =EvenLesJ swi SWI_PrStr mov r1, r10 swi SWI_PrInt ldr r1, =NL swi SWI_PrStr
mov r0, #Stdout ldr r1, =OddLesJ swi SWI_PrStr mov r1, r3 swi SWI_PrInt ldr r1, =NL swi SWI_PrStr
mov R0, # Stdout ldr R1, =EndOfFile swi SWI_PrStr @===========close the file============================== ldr R0,=InputFileHandle ldr R0, [R0] swi SWI_Close Exit: swi 0x11 InFileError: mov R0, #Stdout ldr R1,=FileOpenError swi SWI_PrStr bal Exit
.data .align InputFileHandle: .skip 4 InFileName: .asciz "integers.dat" FileOpenError: .asciz "Failed to open file " EndOfFile: .asciz "End Of File Reached. " NL: .asciz " " Message: .asciz "Hello. " INum: .asciz "Greatest generation " JNum: .asciz "Generation X: " TotInt: .asciz "Generation Z: " greatestJ: .asciz "Integers < (j)= " .end
Using ARMSim# simulator write a program in ARM assembly to perform the following tasks: Some of the Western Cultural Generations are (assume x = age in years): Lost generation is 102 <= x <= 127 Greatest generation is 93 <= x <= 101 Baby boomer generation 53 <= x <= 71 Generation X 38 <= x <= 52 Generation Y 22 <= x <= 36 Generation Z 7 <= x <= 21 Not applicable
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
