This is my homework. Need help! We need to write this program using assembly lan
ID: 3714522 • Letter: T
Question
This is my homework. Need help! We need to write this program using assembly language compiled through ARM Simulator. Any help is appreciated.
The objectives of this project are 1. Use ARM assembly to read string of ASCII characters save it into memory, then extract the hex digits and convert them to integers before processing and skip any none 2. Use ARM assembly instructions to branch to functions and pass the argument to the functions using the stack and either receive the result on the stack or in a register. Implement the following: 1. Place the following character string into an input.txt file. Use them as an input for running operations: 0,3. 4, 5, 6, 8, 9, A, B, C, 1,G,H, a, 2, b, 1,c,7 Read input file convert appropriate characters into hexadecimal integer Have 2 output files. The first one must have three columns: the first is the integer, the second is the summation (using the algorithm n/2 (n1)), and the third column is the factorial of the number. Prior to column headings there should be string(s) of character that lists your class name, number, and your name and last name. The second output file is described in part 4 Use the following functions in this problem: 2. 3. 4. File open File append Number factorial Number summation For each integer, save the results of factorial and summation in a memory array contiguously. For example, the array would read: After processing all the integers, perform an insertion sort on the resultant array. You can find its explanation on the internet. The example below is from Wikipedia for i-1 to length (A)-1 x-Ai] Whilej>-0 and A>x Ali + 1] = A[j] end while End for loop Note: A is the array of integer values calculated by your summation and factorial functions. Write the calculated integer values from the sorted array to the second output file. The integers must be sorted in an ascending order Note: 1. Each subroutine/function must have comment block in the beginning which explains which variables are the inputs that are received from caller and where they are located, and what is (are) the function's output(s), where it is located, and how its returned to the caller Utilize the stack for passing parameters. 2.Explanation / Answer
here is the example of how to read the file input.txt. You can modify the cod efor your project.
@@@ OPEN INPUT FILE, READ INTEGER FROM FILE, PRINT IT, CLOSE INPUT FILE
.equ SWI_Open, 0x66 @open a file
.equ SWI_Close,0x68 @close a file
.equ SWI_PrChr,0x00 @ Write an ASCII char to Stdout
.equ SWI_PrStr, 0x69 @ Write a null-ending string
.equ SWI_PrInt,0x6b @ Write an Integer
.equ SWI_RdInt,0x6c @ Read an Integer from a file
.equ Stdout, 1 @ Set output target to be Stdout
.equ SWI_Exit, 0x11 @ Stop execution
.global _start
.text
_start:
@ print an initial message to the screen
mov R0,#Stdout @print an initial message
ldr R1, =Message1 @ load address of Message1 label
swi SWI_PrStr @ display message to Stdout
@ == Open an input file for reading =============================
@ if problems, print message to Stdout and exit
ldr r0,=InFileName @ set Name for input file
mov r1,#0 @ mode is input
swi SWI_Open @ open file for input
bcs InFileError @ Check Carry-Bit (C): if= 1 then ERROR
@ Save the file handle in memory:
ldr r1,=InputFileHandle @ if OK, load input file handle
str r0,[r1] @ save the file handle
@ == Read integers until end of file =============================
RLoop:
ldr r0,=InputFileHandle @ load input file handle
ldr r0,[r0]
swi SWI_RdInt @ read the integer into R0
bcs EofReached @ Check Carry-Bit (C): if= 1 then EOF reached
@ print the integer to Stdout
mov r1,r0 @ R1 = integer to print
mov R0,#Stdout @ target is Stdout
swi SWI_PrInt
mov R0,#Stdout @ print new line
ldr r1, =NL
swi SWI_PrStr
bal RLoop @ keep reading till end of file
@ == End of file ===============================================
EofReached:
mov R0, #Stdout @ print last message
ldr R1, =EndOfFileMsg
swi SWI_PrStr
@ == Close a file ===============================================
ldr R0, =InFileHandle @ get address of file handle
ldr R0, [R0] @ get value at address
swi SWI_Close
Exit:
swi SWI_Exit @ stop executing
InFileError:
mov R0, #Stdout
ldr R1, =FileOpenInpErrMsg
swi SWI_PrStr
bal Exit @ give up, go to end
.data
.align
InFileHandle: .skip 4
InFileName: .asciz "whatever.txt"
FileOpenInpErrMsg: .asciz "Failed to open input file "
EndOfFileMsg: .asciz "End of file reached "
ColonSpace: .asciz": "
NL: .asciz " " @ new line
Message1: .asciz "Hello World! "
.end
for finding factorial:
For calculating the sum:
mov r0, n // Move the number 'n' into register r0
add r1,r0,#1 // calculate n+1 and store in r1
mul r0, #0.5 // Calculate (n/2) and store in r0
mul r2, r1, r0 // calculate ro*r1 and store in r2 i.e. (n/2)*(n+1)
I hope this much of information helps you in your project. All the best.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.