diff options
| -rw-r--r-- | x86_64/Makefile | 13 | ||||
| -rwxr-xr-x | x86_64/arithmetic | bin | 0 -> 8824 bytes | |||
| -rw-r--r-- | x86_64/arithmetic.o | bin | 0 -> 808 bytes | |||
| -rw-r--r-- | x86_64/arithmetic.s | 22 | ||||
| -rwxr-xr-x | x86_64/exit | bin | 0 -> 8824 bytes | |||
| -rw-r--r-- | x86_64/exit.o | bin | 0 -> 760 bytes | |||
| -rw-r--r-- | x86_64/exit.s | 10 | ||||
| -rwxr-xr-x | x86_64/exponent | bin | 0 -> 8928 bytes | |||
| -rw-r--r-- | x86_64/exponent.o | bin | 0 -> 864 bytes | |||
| -rw-r--r-- | x86_64/exponent.s | 37 | ||||
| -rwxr-xr-x | x86_64/jmp_havoc | bin | 0 -> 9120 bytes | |||
| -rw-r--r-- | x86_64/jmp_havoc.o | bin | 0 -> 1056 bytes | |||
| -rw-r--r-- | x86_64/jmp_havoc.s | 39 | ||||
| -rwxr-xr-x | x86_64/mul_by_add | bin | 0 -> 8976 bytes | |||
| -rw-r--r-- | x86_64/mul_by_add.o | bin | 0 -> 904 bytes | |||
| -rw-r--r-- | x86_64/mul_by_add.s | 25 | ||||
| -rwxr-xr-x | x86_64/reg_size | bin | 0 -> 8896 bytes | |||
| -rw-r--r-- | x86_64/reg_size.o | bin | 0 -> 800 bytes | |||
| -rw-r--r-- | x86_64/reg_size.s | 17 |
19 files changed, 163 insertions, 0 deletions
diff --git a/x86_64/Makefile b/x86_64/Makefile new file mode 100644 index 0000000..4096a79 --- /dev/null +++ b/x86_64/Makefile @@ -0,0 +1,13 @@ + +OBJS = exit.o arithmetic.o reg_size.o jmp_havoc.o exponent.o mul_by_add.o + +all: $(OBJS) + ld -o exit exit.o + ld -o arithmetic arithmetic.o + ld -o reg_size reg_size.o + ld -o jmp_havoc jmp_havoc.o + ld -o exponent exponent.o + ld -o mul_by_add mul_by_add.o + +clean: + rm $(OBJS) diff --git a/x86_64/arithmetic b/x86_64/arithmetic Binary files differnew file mode 100755 index 0000000..b8fd40a --- /dev/null +++ b/x86_64/arithmetic diff --git a/x86_64/arithmetic.o b/x86_64/arithmetic.o Binary files differnew file mode 100644 index 0000000..9d258f5 --- /dev/null +++ b/x86_64/arithmetic.o diff --git a/x86_64/arithmetic.s b/x86_64/arithmetic.s new file mode 100644 index 0000000..34216f1 --- /dev/null +++ b/x86_64/arithmetic.s @@ -0,0 +1,22 @@ +# Simple program exercising CPU's arithmetic instructions + +.globl _start + +.section .text + +_start: + movq $3, %rdi + movq %rdi, %rax + mulq %rdi + movq $2, %rdi + addq %rdi, %rax + movq $4, %rdi + mulq %rdi + + movq $10, %rax + movq $3, %rdi + divq %rdi # Remainder goes to %rdx + movq %rax, %rdi + + mov $60, %rax + syscall diff --git a/x86_64/exit b/x86_64/exit Binary files differnew file mode 100755 index 0000000..c9bb3ab --- /dev/null +++ b/x86_64/exit diff --git a/x86_64/exit.o b/x86_64/exit.o Binary files differnew file mode 100644 index 0000000..44033df --- /dev/null +++ b/x86_64/exit.o diff --git a/x86_64/exit.s b/x86_64/exit.s new file mode 100644 index 0000000..d9c594f --- /dev/null +++ b/x86_64/exit.s @@ -0,0 +1,10 @@ +# Simple program that just exits with a simple status code + +.globl _start + +.section .text + +_start: + movq $60, %rax # sys_exit + movq $66, %rdi + syscall diff --git a/x86_64/exponent b/x86_64/exponent Binary files differnew file mode 100755 index 0000000..ce3f124 --- /dev/null +++ b/x86_64/exponent diff --git a/x86_64/exponent.o b/x86_64/exponent.o Binary files differnew file mode 100644 index 0000000..516d6c5 --- /dev/null +++ b/x86_64/exponent.o diff --git a/x86_64/exponent.s b/x86_64/exponent.s new file mode 100644 index 0000000..e469d26 --- /dev/null +++ b/x86_64/exponent.s @@ -0,0 +1,37 @@ +# Compute a^b, where %rbx=a and %rcx=b +# +# Result is added to the accumulator (%rax) + + +.globl _start + +.section .text + +_start: + movq $2, %rbx # Base + movq $5, %rcx # Exponent + + movq $1, %rax # Initialize accumulator, take advantage of the fact + # that anything to the power of 0 is 1. + + # We just need to run this once, as decq will set ZF if %rcx reaches + # zero, and the jmp instruction does nothing with the ZF + cmpq $0, %rcx + je complete + +mainloop: + + # Multiply %rbx by %rax, and stores the result in %rax + # Hence %rax is the accumulator register + mulq %rbx + + # loopq instruction is very nice, in a single instruction it does: + # - decrement %rcx - The counter register - + # - compare %rcx to zero + # - Jump to the location specified if after decrementing %rcx is not 0 + loopq mainloop + +complete: + movq %rax, %rdi + movq $60, %rax + syscall diff --git a/x86_64/jmp_havoc b/x86_64/jmp_havoc Binary files differnew file mode 100755 index 0000000..6c22ca7 --- /dev/null +++ b/x86_64/jmp_havoc diff --git a/x86_64/jmp_havoc.o b/x86_64/jmp_havoc.o Binary files differnew file mode 100644 index 0000000..1e65228 --- /dev/null +++ b/x86_64/jmp_havoc.o diff --git a/x86_64/jmp_havoc.s b/x86_64/jmp_havoc.s new file mode 100644 index 0000000..6dd734d --- /dev/null +++ b/x86_64/jmp_havoc.s @@ -0,0 +1,39 @@ +# Play around with jumps + +.section .text +.globl _start + +_start: + movq $25, %rax + jmp thelabel + +somewhere: + movq %rax, %rdi + jmp anotherlabel + +label1: + addq %rbx, %rax + movq $5, %rbx + jmp here + +labellabel: + syscall + +anotherlabel: + movq $60, %rax + jmp labellabel + +thelabel: + movq %rax, %rbx + jmp there + +here: + divq %rbx + jmp somewhere + +there: + addq $5, %rbx + jmp label1 + +anywhere: + jmp thelabel diff --git a/x86_64/mul_by_add b/x86_64/mul_by_add Binary files differnew file mode 100755 index 0000000..1850861 --- /dev/null +++ b/x86_64/mul_by_add diff --git a/x86_64/mul_by_add.o b/x86_64/mul_by_add.o Binary files differnew file mode 100644 index 0000000..7d7e01a --- /dev/null +++ b/x86_64/mul_by_add.o diff --git a/x86_64/mul_by_add.s b/x86_64/mul_by_add.s new file mode 100644 index 0000000..3e8c360 --- /dev/null +++ b/x86_64/mul_by_add.s @@ -0,0 +1,25 @@ +# Do a multiplication without using mulq, resulting in a * b +.section .text +.globl _start + +.set OP, 1 # Set here the numbers to +.set OP2, 1 # be multiplied + +_start: + movq $OP2, %rcx + movq $0, %rax + + # We can't rely on loopq to drop exit the loop in case OP2 + # is 0, because the first iteraction will cause %rcx to be -1 + cmpq $OP2, %rax + je exit + + +addloop: + addq $OP, %rax + loopq addloop + +exit: + movq %rax, %rdi + movq $60, %rax + syscall diff --git a/x86_64/reg_size b/x86_64/reg_size Binary files differnew file mode 100755 index 0000000..eec38b7 --- /dev/null +++ b/x86_64/reg_size diff --git a/x86_64/reg_size.o b/x86_64/reg_size.o Binary files differnew file mode 100644 index 0000000..1622ccf --- /dev/null +++ b/x86_64/reg_size.o diff --git a/x86_64/reg_size.s b/x86_64/reg_size.s new file mode 100644 index 0000000..e374922 --- /dev/null +++ b/x86_64/reg_size.s @@ -0,0 +1,17 @@ +# Program to play around with different register sizes + +.set exit_num, 60 + +.section .text +.globl _start + +_start: + movw $0b0000101000000101, %bx #10d and 5d into high and low registers + addb %bh, %bl + movb $0, %bh + + # %bh now contains 10+5, use it as an argument to exit() + + movq %rbx, %rdi + movq $exit_num, %rax + syscall |
