csci2021/ArchLab/archlab-handout/sim/y86-code/asumi.yo

39 lines
1.9 KiB
Text
Raw Normal View History

2018-01-29 23:45:27 +00:00
| # Execution begins at address 0
0x000: | .pos 0
0x000: 30f40001000000000000 | irmovq stack, %rsp # Set up stack pointer
0x00a: 803800000000000000 | call main # Execute main program
0x013: 00 | halt # Terminate program
|
| # Array of 4 elements
0x018: | .align 8
0x018: 0d000d000d000000 | array: .quad 0x000d000d000d
0x020: c000c000c0000000 | .quad 0x00c000c000c0
0x028: 000b000b000b0000 | .quad 0x0b000b000b00
0x030: 00a000a000a00000 | .quad 0xa000a000a000
|
0x038: 30f71800000000000000 | main: irmovq array,%rdi
0x042: 30f60400000000000000 | irmovq $4,%rsi
0x04c: 805600000000000000 | call sum # sum(array, 4)
0x055: 90 | ret
|
| /* $begin sumi-ys */
| # long sum(long *start, long count)
| # start in %rdi, count in %rsi
0x056: | sum:
0x056: 6300 | xorq %rax,%rax # sum = 0
0x058: 6266 | andq %rsi,%rsi # Set condition codes
0x05a: 708300000000000000 | jmp test
0x063: | loop:
0x063: 50a70000000000000000 | mrmovq (%rdi),%r10 # Get *start
0x06d: 60a0 | addq %r10,%rax # Add to sum
0x06f: c0f70800000000000000 | iaddq $8,%rdi # start++
0x079: c0f6ffffffffffffffff | iaddq $-1,%rsi # count--
0x083: | test:
0x083: 746300000000000000 | jne loop # Stop when 0
0x08c: 90 | ret
| /* $end sumi-ys */
|
| # The stack starts here and grows to lower addresses
0x100: | .pos 0x100
0x100: | stack: