Lab 3
Lab 3
Getting Started: Unpacking the Examples
To begin, I unpacked the provided example files on the SPO600 servers:
cd ~
tar xvf /public/spo600-assembler-lab-examples.tgz
This produced the following directory structure:
spo600
└── examples
└── hello
├── assembler
│ ├── aarch64
│ │ ├── hello.s
│ │ └── Makefile
│ ├── Makefile
│ └── x86_64
│ ├── hello-gas.s
│ ├── hello-nasm.s
│ └── Makefile
└── c
├── hello2.c
├── hello3.c
├── hello.c
└── Makefile
I first built and ran the C versions of the "Hello World" program:
cd ~/spo600/examples/hello/c
make
./hello
./hello2
./hello3
Next, I used objdump
to disassemble the binaries and inspect the <main>
section:
objdump -d hello
objdump -d hello2
objdump -d hello3
I navigated to the x86_64 directory to review and build the assembly language programs:
cd ~/spo600/examples/hello/assembler/x86_64
make
./hello-gas
./hello-nasm
Disassembling the object code:
objdump -d hello-gas
objdump -d hello-nasm
This showed a more concise code compared to the C binaries, with fewer additional instructions.
Building and Running
Similarly, I built and ran the AArch64 assembly language program:
cd ~/spo600/examples/hello/assembler/aarch64
make
./hello
Disassembling the object code:
objdump -d hello
.text
.globl _start
min = 0
max = 10
_start:
mov x19, min
loop:
ldr x0, =msg
bl puts
add x19, x19, 1
cmp x19, max
b.ne loop
mov x0, 0
mov x8, 93
svc 0
msg:
.asciz "Loop"
.text
.globl _start
min = 0
max = 10
_start:
mov x19, min
loop:
add x0, x19, '0'
bl putchar
mov x0, '\n'
bl putchar
add x19, x19, 1
cmp x19, max
b.ne loop
mov x0, 0
mov x8, 93
svc 0
putchar:
mov x8, 64
svc 0
ret
Optional Challenge
.text
.globl _start
_start:
mov x20, 1 /* Multiplier */
mov x21, 1 /* Multiplicand */
table:
mov x0, x20
bl print_number
mov x0, ' x '
bl print_string
mov x0, x21
bl print_number
mov x0, ' = '
bl print_string
mul x0, x20, x21
bl print_number
mov x0, '\n'
bl putchar
add x21, x21, 1
cmp x21, 13
b.eq next_table
b table
next_table:
mov x21, 1
add x20, x20, 1
cmp x20, 13
b.ne table
/* Exit */
mov x0, 0
mov x8, 93
svc 0
print_number:
ret
print_string:
ret
Комментарии
Отправить комментарий