Skip to content

Commit

Permalink
7 part
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAX committed Dec 11, 2014
1 parent 3361dcf commit b86b6aa
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 4 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ Learning assembly for linux-x64
Examples
==============

* hello - hello world;
* sum - sum of two numbers;
* stack - sum of command line arguments;
* reverse - reverse string.
* hello - hello world [Say hello to x86_64 Assembly part 1](http://0xax.blogspot.com/2014/08/say-hello-to-x64-assembly-part-1.html);
* sum - sum of two numbers [Say hello to x86_64 Assembly part 2](http://0xax.blogspot.com/2014/09/say-hello-to-x64-assembly-part-2.html);
* stack - sum of command line arguments [Say hello to x86_64 Assembly part 3](http://0xax.blogspot.com/2014/09/say-hello-to-x64-assembly-part-3.html);
* reverse - reverse string [Say hello to x86_64 Assembly part 4](http://0xax.blogspot.com/2014/11/say-hello-to-x64-assembly-part-4.html);
* casm - c and assembly interaction [Say hello to x86_64 Assembly part 6](http://0xax.blogspot.com/2014/11/say-hello-to-x64-assembly-part-4.html).

[@0xAX](https://twitter.com/0xAX)
11 changes: 11 additions & 0 deletions casm/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This is "C with assermbly interaction" application.

Build it with: `make`

* casm1 - call C function from asm
* casm2 - gcc inline assembly
* casm3 - call asm function from C

More details at - [Say hello to x86_64 Assembly part 6](http://0xax.blogspot.com/2014/11/say-hello-to-x64-assembly-part-4.html)

[@0xAX](http://twitter.com/0xAX)
7 changes: 7 additions & 0 deletions casm/Readme.md~
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This is "C with assermbly interaction" application.

Build it with: `make`

More details at - [Say hello to x86_64 Assembly part 6](http://0xax.blogspot.com/2014/11/say-hello-to-x64-assembly-part-4.html)

[@0xAX](http://twitter.com/0xAX)
8 changes: 8 additions & 0 deletions casm/casm1/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
buildAsmc:
gcc -c casm.c -o c.o
nasm -f elf64 casm.asm -o casm.o
ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -lc casm.o c.o -o casm

clean:
rm -rf *.o
rm -rf casm
8 changes: 8 additions & 0 deletions casm/casm1/Makefile~
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
buildAsmc:
gcc -c casm.c -o c.o
nasm -f elf64 casm.asm -o casm.o
ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -lc casm.o c.o -o casm

clean:
rm -rf *.o
rm -rf casm
13 changes: 13 additions & 0 deletions casm/casm1/casm.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
global _start

extern print

section .text

_start:
call print

;; exit
mov rax, 60
mov rdi, 0
syscall
8 changes: 8 additions & 0 deletions casm/casm1/casm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdio.h>

extern int print();

int print() {
printf("Hello World\n");
return 0;
}
2 changes: 2 additions & 0 deletions casm/casm2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build:
gcc casm.c -o casm
2 changes: 2 additions & 0 deletions casm/casm2/Makefile~
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build:
gcc casm.c -o casm
17 changes: 17 additions & 0 deletions casm/casm2/casm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <string.h>

int main() {
char* str = "Hello World\n";
long len = strlen(str);
int ret = 0;

__asm__("movq $1, %%rax \n\t"
"movq $1, %%rdi \n\t"
"movq %1, %%rsi \n\t"
"movl %2, %%edx \n\t"
"syscall"
: "=g"(ret)
: "g"(str), "g" (len));

return 0;
}
8 changes: 8 additions & 0 deletions casm/casm2/casm.c~
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdio.h>

extern int print();

int print() {
printf("Hello World\n");
return 0;
}
3 changes: 3 additions & 0 deletions casm/casm3/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build:
nasm -f elf64 -o casm.o casm.asm
gcc casm.o casm.c -o casm
3 changes: 3 additions & 0 deletions casm/casm3/Makefile~
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build:
nasm -f elf64 -o casm.o casm.asm
gcc casm.o casm.c -o casm
15 changes: 15 additions & 0 deletions casm/casm3/casm.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
global printHelloWorld

section .text
printHelloWorld:
;; 1 arg
mov r10, rdi
;; 2 arg
mov r11, rsi
;; call write syscall
mov rax, 1
mov rdi, 1
mov rsi, r10
mov rdx, r11
syscall
ret
13 changes: 13 additions & 0 deletions casm/casm3/casm.asm~
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
global _start

extern print

section .text

_start:
call print

;; exit
mov rax, 60
mov rdi, 0
syscall
8 changes: 8 additions & 0 deletions casm/casm3/casm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <string.h>

int main() {
char* str = "Hello World\n";
int len = strlen(str);
printHelloWorld(str, len);
return 0;
}
8 changes: 8 additions & 0 deletions casm/casm3/casm.c~
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdio.h>

extern int print();

int print() {
printf("Hello World\n");
return 0;
}

0 comments on commit b86b6aa

Please sign in to comment.