64-Bit Assembly Language Lab
Heavendeep Kaur Munjal
Posted on March 20, 2024
The very first thing to do is setup the the servers:
Go to the folder: cd spo600/examples/hello/assembler/
Then using make
building the c files:
Open the files using cat
command and By objdump -d objectfile
we can look at the code:
The code to include loop index values, showing each digit from 0 to 30 in AArch64 assembly language:
.text
.global _start
start = 0 /* loop index starting value */
max = 31 /* loop exits when the index hits this number */
_start:
mov x3,start /* set loop index */
loop:
mov x9,10 /* store divisor in register */
udiv x10,x3,x9 /* divide and store quotient in register */
msub x11,x9,x10,x3 /* store remainder in register */
adr x1,msg /* message location */
cmp x10,0 /* check if quotient is 0 */
b.eq next /* jump if quotient is 0 */
add x12,x10,0x30 /* convert to ascii and store in register */
strb w12,[x1,6] /* place quotient in msg */
next:
add x13,x11,0x30 /* convert to ascii and store in register */
strb w13,[x1,7] /* place remainder in msg */
mov x2,len /* message length */
mov x0,1 /* file descriptor stdout */
mov x8,64 /* syscall sys_write */
svc 0 /* syscall */
add x3,x3,1 /* increment index */
cmp x3,max /* check if index is at max */
b.ne loop /* loop if index not at max */
mov x0,0 /* exit status */
mov x8,93 /* syscall sys_exit */
svc 0 /* syscall */
.data
msg: .ascii "Loop: \n"
.set len, . - msg
In x86_64 assembly language program:
.text
.global _start
start = 0 /* loop index starting value */
max = 31 /* loop exits when the index hits this number */
_start:
mov $start,%r15 /* set loop index */
loop:
mov $0,%rdx /* clear register */
mov %r15,%rax /* store dividend in register */
mov $10,%r10 /* store divisor in register */
div %r10 /* divide */
mov %rax,%r11 /* store quotient in register */
mov %rdx,%r12 /* store remainder in register */
cmp $0,%r11 /* check if quotient is 0 */
je next /* jump if quotient is 0 */
add $0x30,%r11 /* convert to ascii */
mov %r11b,msg+6 /* place quotient in msg */
next:
add $0x30,%r12 /* convert to ascii */
mov %r12b,msg+7 /* place remainder in msg */
mov $len,%rdx /* message length */
mov $msg,%rsi /* message location */
mov $1,%rdi /* file descriptor stdout */
mov $1,%rax /* syscall sys_write */
syscall /* syscall */
inc %r15 /* increment index */
cmp $max,%r15 /* check if index is at max */
jne loop /* loop if index not at max */
mov $0,%rdi /* exit status */
mov $60,%rax /* syscall sys_exit */
syscall /* syscall */
.data
msg: .ascii "Loop: \n"
.set len , . - msg
In conclusion, exploring assembly programming across diverse architectures provided invaluable insights into low-level computing. From the nostalgic simplicity of 6502 to the complex optimizations of x86_64 and AArch64, each architecture challenged and expanded my understanding, enriching my programming journey with hands-on experience and newfound
Posted on March 20, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024