Lab 4 in class portion
This lab was very difficult for me, as the progress of this class feels very fast and if I'm not up to date I feel pretty left behind in the material and I wasn't of much help during this in class portion. My group mates completed a good portion of the code during the lab without much input from me. I took some time to review and study the material for the aarch 64 and x86 64 assemblers and when I took on this lab again I felt much more prepared and ready to do it. Below is my completed portion of the in class section of the assignment.
.text
.globl _start
min = 0 /* starting value for the loop index; **note that this is a symbol (constant)**, not a variable */
max = 10 /* loop exits when the index hits this number (loop condition is i<max) */
_start:
mov x19, min
loop:
/* ... body of the loop ... do something useful here ... */
mov x3, x19 /*store value from x19 temporarily in x3*/
add x3, x3, 48 /* x3 has ascii for character */
adr x4, msg /* message location (memory address) */
strb w3, [x4, 6]
mov x0, 1 /* file descriptor: 1 is stdout */
/* ascii for zero is 48 */
adr x1, msg /* message location (memory address) */
mov x2, len /* message length (bytes) */
mov x8, 64 /* write is syscall #64 */
svc 0 /* invoke syscall */
add x19, x19, 1 /* increment the loop counter */
cmp x19, max /* see if we've hit the max */
b.ne loop /* if not, then continue the loop */
mov x0, 0 /* set exit status to 0 */
mov x8, 93 /* exit is syscall #93 */
svc 0 /* invoke syscall */
.data
msg: .ascii "Loop: \n"
len= . - msg
Once I got the hang of it the code was much easier to understand. The code has a two main constant symbols being min and max with values 0 and 10 respectively to handle the looping. mov x19, min initializes the loop counter to the min value, then enters the loop. mov x3, 19 will copy the value of the loop counter into x3 so that it can be altered without changing the actual loop counter. It then adds the ASCII value for 0 (48) into x3 to convert the integer to ASCII. The code then loads the address of the string into the register x4 and then stores the ASCII value of the loop index into w3 which is in Loop: \n. Then the program calls to write the message and then it will increment and compare the current value with the max value.
Comments
Post a Comment