Wednesday 26 February 2020

Week - 7 Lecture (Lab 5)

This week there was no lab due to Family day's holiday so the Lab 5 was supposed to be worked on in the lecture period. This were the required steps for Lab 5:

Here is a basic loop in AArch64 assembler - this loops from 0 to 9, using r19 as the index (loop control) counter:
.text
.globl _start

min = 0                          /* starting value for the loop index; note that this is a symbol (constant), not a variable */
max = 30                         /* 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 ... */

    add     x19, x19, 1
    cmp     x19, max
    b.ne    loop

    mov     x0, 0           /* status -> 0 */
    mov     x8, 93          /* exit is syscall #93 */
    svc     0               /* invoke syscall */
This code doesn't actually do anything while looping, because the body of the loop is empty. On an AArch64 machine, combine this code with code from the "Hello World" assembley-language example, so that it prints a word each time it loops:
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Then modify the message so that it includes the loop index values, showing each digit from 0 to 9 like this:
Loop: 0
Loop: 1
Loop: 2
Loop: 3
Loop: 4
Loop: 5
Loop: 6
Loop: 7
Loop: 8
Loop: 9

Now we had a list of servers we could choose from so we decided to go with aarchie.
Then after taking reference from both the loop example given and the hello world program we were able to print the iterations of loop without numbers. Here is the code:

.text
.globl _start

min = 0                          /* starting value for the loop index; note that this is a symbol (constant), not a variable */
max = 30                         /* loop exits when the index hits this number (loop condition is i<max) */

_start:

    mov     x19, min

loop:

        mov     x0, 1           /* file descriptor: 1 is stdout */
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
    cmp     x19, max
    b.ne    loop

    mov     x0, 0           /* status -> 0 */
    mov     x8, 93          /* exit is syscall #93 */
    svc     0               /* invoke syscall */

.data
msg: .ascii      "loop \n"
len= . - msg

the text is stored in the msg label and .ascii acts as a dcb. then _start. declares the start of the program and the loop label uses the message and its length to do a syscall to print it to the screen and one gets added to the register used for iteration and this keeps on going until the loop is finished i.e. comparison between max and register value. Well we were trying different ways on how to get the number printed besides the loop but could only managed to go this far until the lecture was over and we were told this lab would be continued until the lab period after study week so we had a lot of time to think over this.
Though the syntax looks a bit scary for now for this architecture it is just a matter of time before we get used to these instructions and then everything should be fine.

No comments:

Post a Comment