SPO600 – Lab 3

AArch64 code:

.globl _start

beg = 0
max = 31

mov x28,beg
mov w20,0
add w26,w20,0x30


// div
mov x20, 10
udiv x21,x28,x20
msub x22,x20,x21,x28

// msg
add w23,w21,0x30
add w24,w22,0x30
adr x25,msg
strb w24,[x25,7]
cmp w23,w26
beq continue
strb w23,[x25,6]

// write
mov x2,len
adr x1,msg
mov x0,1
mov x8,64
svc 0

// loop
add x28,x28,1
cmp x28,max
bne loop

mov x0,0
mov x8,93
svc 0

msg: .ascii “Loop: \n”
len = . – msg


Disassembly of section .text:

00000000004000b0 <_start>:
4000b0: d280001c mov x28, #0x0 // #0
4000b4: 52800014 mov w20, #0x0 // #0
4000b8: 1100c29a add w26, w20, #0x30

00000000004000bc <loop>:
4000bc: d2800154 mov x20, #0xa // #10
4000c0: 9ad40b95 udiv x21, x28, x20
4000c4: 9b15f296 msub x22, x20, x21, x28
4000c8: 1100c2b7 add w23, w21, #0x30
4000cc: 1100c2d8 add w24, w22, #0x30
4000d0: 10080219 adr x25, 410110 <msg>
4000d4: 39001f38 strb w24, [x25,#7]
4000d8: 6b1a02ff cmp w23, w26
4000dc: 54000040 b.eq 4000e4 <continue>
4000e0: 39001b37 strb w23, [x25,#6]

00000000004000e4 <continue>:
4000e4: d2800122 mov x2, #0x9 // #9
4000e8: 10080141 adr x1, 410110 <msg>
4000ec: d2800020 mov x0, #0x1 // #1
4000f0: d2800808 mov x8, #0x40 // #64
4000f4: d4000001 svc #0x0
4000f8: 9100079c add x28, x28, #0x1
4000fc: f1007f9f cmp x28, #0x1f
400100: 54fffde1 b.ne 4000bc <loop>
400104: d2800000 mov x0, #0x0 // #0
400108: d2800ba8 mov x8, #0x5d // #93
40010c: d4000001 svc #0x0

As you can see there is no difference in the assembly code between objdump and source code, except for the constants that were referenced as a memory link.


x86_64 code:

Since the change I forgot to give permissions to xerxes from matrix so I am not able to connect while I am not in seneca. Therefore, I am not able to provide the disassembly part. Luckily, I was smart enough to save a copy of the source code in betty.

.globl _start

start = 0
max = 31

mov $start,%r15
and $0,%r12
add $0x30,%r12
// div
and $0,%rdx
mov %r15,%rax
mov $10,%r10
div %r10
mov %rax,%r14
mov %rdx,%r13

// msg
add $0x30,%r14
add $0x30,%r13
mov %r13b,msg+7

// skip if first digit is 0
cmp %r12,%r14
je continue
mov %r14b,msg+6

// write
mov $len,%rdx
mov $msg,%rsi
mov $1,%rdi
mov $1,%rax

// loop
inc %r15
cmp $max,%r15
jne loop

// exit
mov $0,%rdi
mov $60,%rax

msg: .ascii “Loop: \n”
len = . – msg

I know it works. I had already tried both of them, I just never made the blog about them.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s