csci2021/ArchLab/archlab-handout/sim/y86-code/abs-asum-jmp.yo
Michael Zhang 1fa36db752
f
2018-01-29 17:45:27 -06:00

46 lines
2.5 KiB
Text

| # Modification of asum code to compute absolute values of entries.
| # This version uses a conditional jump
| # Execution begins at address 0
0x000: | .pos 0
0x000: 30f40002000000000000 | 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 0x0000000d000d000d
0x020: 40ff3fff3fffffff | .quad 0xffffff3fff3fff40 # -0x000000c000c000c0
0x028: 000b000b000b0000 | .quad 0x00000b000b000b00
0x030: 0060ff5fff5fffff | .quad 0xffff5fff5fff6000 # -0x0000a000a000a000
|
0x038: 30f71800000000000000 | main: irmovq array,%rdi
0x042: 30f60400000000000000 | irmovq $4,%rsi
0x04c: 805600000000000000 | call absSum # absSum(array, 4)
0x055: 90 | ret
| /* $begin abs-sum-jmp-ys */
| # long absSum(long *start, long count)
| # start in %rdi, count in %rsi
0x056: | absSum:
0x056: 30f80800000000000000 | irmovq $8,%r8 # Constant 8
0x060: 30f90100000000000000 | irmovq $1,%r9 # Constant 1
0x06a: 6300 | xorq %rax,%rax # sum = 0
0x06c: 6266 | andq %rsi,%rsi # Set condition codes
0x06e: 709600000000000000 | jmp test
0x077: | loop:
0x077: 50a70000000000000000 | mrmovq (%rdi),%r10 # x = *start
0x081: 63bb | xorq %r11,%r11 # Constant 0
0x083: 61ab | subq %r10,%r11 # -x
0x085: 719000000000000000 | jle pos # Skip if -x <= 0
0x08e: 20ba | rrmovq %r11,%r10 # x = -x
0x090: | pos:
0x090: 60a0 | addq %r10,%rax # Add to sum
0x092: 6087 | addq %r8,%rdi # start++
0x094: 6196 | subq %r9,%rsi # count--
0x096: | test:
0x096: 747700000000000000 | jne loop # Stop when 0
0x09f: 90 | ret
| /* $end abs-sum-jmp-ys */
|
| # The stack starts here and grows to lower addresses
0x200: | .pos 0x200
0x200: | stack: