Skip to content

Commit

Permalink
Code from Home Run
Browse files Browse the repository at this point in the history
  • Loading branch information
JudgeGroovyman committed Oct 4, 2019
1 parent 2abb5c7 commit 8e6105d
Show file tree
Hide file tree
Showing 72 changed files with 1,319 additions and 0 deletions.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added asm/Calling C from Asm with Int Parameter/example
Binary file not shown.
Binary file added asm/Calling C from Asm with Int Parameter/example.o
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions asm/Calling C from Asm with Int Parameter/myLibrary.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "myLibrary.h"
#include <stdio.h>
int foo(int a) {
printf ("\n");
if (a < 100) {
printf("Number is: %i\n",a);
for (int i = 0; i < a; i++) {
printf("d");
}
printf("\n");
}
else {
printf("Number very large: %i\n",a);
}
return 0;
}
int doo(char * a) {
printf("Hey | %s |\n",a);
return 0;
}
5 changes: 5 additions & 0 deletions asm/Calling C from Asm with Int Parameter/myLibrary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifndef WHATEVER_H_INCLUDED
#define WHATEVER_H_INCLUDED
int foo(int a);
int doo(char * a);
#endif
Binary file not shown.
18 changes: 18 additions & 0 deletions asm/Calling C from Asm with Int Parameter/myLibraryExample.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; See Readme for instructions

global _main
extern _foo

section .text
_main:
sub rsp, 8

mov rdi, 0x55 ; Use this instead of 'mov rdi, message'
call _foo
add rsp, 8
ret

section .data
message:
default rel ; Add 'default rel' under label
db 0x2
13 changes: 13 additions & 0 deletions asm/Calling C from Asm with Int Parameter/myLibraryExample.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// --------------------------------------------------
// gcc -c myLibrary.c -o myLibrary.o
// gcc -c myLibraryExample.c -o example.o
// gcc example.o myLibrary.o -o example
// ./example
// --------------------------------------------------

#include "myLibrary.h"

int main() {
foo(11);
return 0;
}
Binary file not shown.
22 changes: 22 additions & 0 deletions asm/Calling C from Asm with Int Parameter/myLibraryExample2.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
; ------------------------------------------------------------------------------
; gcc -c myLibrary.c -o myLibrary.o

; /usr/local/bin/nasm -f macho64 myLibraryExample.asm && gcc -arch x86_64 -o exampleAsm myLibraryExample.o myLibrary.o && ./exampleAsm
; ------------------------------------------------------------------------------

global _main
extern _foo

section .text
_main:
sub rsp, 8

lea rdi, [message] ; Use this instead of 'mov rdi, message'
call _foo
add rsp, 8
ret

section .data
message:
default rel ; Add 'default rel' under label
db "Hola, mundo",0
27 changes: 27 additions & 0 deletions asm/Calling C from Asm with Int Parameter/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

To Compile the library:
gcc -c myLibrary.c -o myLibrary.o

For just the C Example:
Compile
gcc -c myLibraryExample.c -o example.o
Link
gcc example.o myLibrary.o -o example
Run
./example

For just the Asm Example:
Compile
/usr/local/bin/nasm -f macho64 myLibraryExample.asm
Link
gcc -arch x86_64 -o exampleAsm myLibraryExample.o myLibrary.o
Run:
./exampleAsm
All:
nasm -f macho64 myLibraryExample.asm && gcc -arch x86_64 -o exampleAsm myLibraryExample.o myLibrary.o && ./exampleAsm

Compile the library and CLR the asm:
gcc -c myLibrary.c -o myLibrary.o && nasm -f macho64 myLibraryExample.asm && gcc -arch x86_64 -o exampleAsm myLibraryExample.o myLibrary.o && ./exampleAsm



Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions asm/Calling C from Asm with String Parameter/myLibrary.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "myLibrary.h"
#include <stdio.h>
int foo(int a) {
printf("Hey %d\n",a);
return 0;
}
int doo(char * a) {
printf("Hey | %s |\n",a);
return 0;
}
5 changes: 5 additions & 0 deletions asm/Calling C from Asm with String Parameter/myLibrary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifndef WHATEVER_H_INCLUDED
#define WHATEVER_H_INCLUDED
int foo(int a);
int doo(char * a);
#endif
Binary file not shown.
18 changes: 18 additions & 0 deletions asm/Calling C from Asm with String Parameter/myLibraryExample.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; See Readme for instructions

global _main
extern _doo

section .text
_main:
sub rsp, 8

lea rdi, [message] ; Use this instead of 'mov rdi, message'
call _doo
add rsp, 8
ret

section .data
message:
default rel ; Add 'default rel' under label
db "Hey there, World!",0
13 changes: 13 additions & 0 deletions asm/Calling C from Asm with String Parameter/myLibraryExample.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// --------------------------------------------------
// gcc -c myLibrary.c -o myLibrary.o
// gcc -c myLibraryExample.c -o example.o
// gcc example.o myLibrary.o -o example
// ./example
// --------------------------------------------------

#include "myLibrary.h"

int main() {
foo(11);
return 0;
}
Binary file not shown.
22 changes: 22 additions & 0 deletions asm/Calling C from Asm with String Parameter/myLibraryExample2.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
; ------------------------------------------------------------------------------
; gcc -c myLibrary.c -o myLibrary.o

; /usr/local/bin/nasm -f macho64 myLibraryExample.asm && gcc -arch x86_64 -o exampleAsm myLibraryExample.o myLibrary.o && ./exampleAsm
; ------------------------------------------------------------------------------

global _main
extern _foo

section .text
_main:
sub rsp, 8

lea rdi, [message] ; Use this instead of 'mov rdi, message'
call _foo
add rsp, 8
ret

section .data
message:
default rel ; Add 'default rel' under label
db "Hola, mundo",0
27 changes: 27 additions & 0 deletions asm/Calling C from Asm with String Parameter/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

To Compile the library:
gcc -c myLibrary.c -o myLibrary.o

For just the C Example:
Compile
gcc -c myLibraryExample.c -o example.o
Link
gcc example.o myLibrary.o -o example
Run
./example

For just the Asm Example:
Compile
/usr/local/bin/nasm -f macho64 myLibraryExample.asm
Link
gcc -arch x86_64 -o exampleAsm myLibraryExample.o myLibrary.o
Run:
./exampleAsm
All:
nasm -f macho64 myLibraryExample.asm && gcc -arch x86_64 -o exampleAsm myLibraryExample.o myLibrary.o && ./exampleAsm

Compile the library and CLR the asm:
gcc -c myLibrary.c -o myLibrary.o && nasm -f macho64 myLibraryExample.asm && gcc -arch x86_64 -o exampleAsm myLibraryExample.o myLibrary.o && ./exampleAsm



Binary file added asm/Calling My C Library From Assembly/example
Binary file not shown.
Binary file added asm/Calling My C Library From Assembly/example.o
Binary file not shown.
Binary file added asm/Calling My C Library From Assembly/exampleAsm
Binary file not shown.
6 changes: 6 additions & 0 deletions asm/Calling My C Library From Assembly/myLibrary.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "myLibrary.h"
#include <stdio.h>
int foo(int a) {
printf("Hey %d\n",a);
return 0;
}
4 changes: 4 additions & 0 deletions asm/Calling My C Library From Assembly/myLibrary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef WHATEVER_H_INCLUDED
#define WHATEVER_H_INCLUDED
int foo(int a);
#endif
Binary file added asm/Calling My C Library From Assembly/myLibrary.o
Binary file not shown.
22 changes: 22 additions & 0 deletions asm/Calling My C Library From Assembly/myLibraryExample.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
; ------------------------------------------------------------------------------
; gcc -c myLibrary.c -o myLibrary.o

; /usr/local/bin/nasm -f macho64 myLibraryExample.asm && gcc -arch x86_64 -o exampleAsm myLibraryExample.o myLibrary.o && ./exampleAsm
; ------------------------------------------------------------------------------

global _main
extern _foo

section .text
_main:
sub rsp, 8

lea rdi, [message] ; Use this instead of 'mov rdi, message'
call _foo
add rsp, 8
ret

section .data
message:
default rel ; Add 'default rel' under label
db "Hola, mundo",0
13 changes: 13 additions & 0 deletions asm/Calling My C Library From Assembly/myLibraryExample.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// --------------------------------------------------
// gcc -c myLibrary.c -o myLibrary.o
// gcc -c myLibraryExample.c -o example.o
// gcc example.o myLibrary.o -o example
// ./example
// --------------------------------------------------

#include "myLibrary.h"

int main() {
foo(11);
return 0;
}
Binary file not shown.
22 changes: 22 additions & 0 deletions asm/Calling My C Library From Assembly/myLibraryExample2.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
; ------------------------------------------------------------------------------
; gcc -c myLibrary.c -o myLibrary.o

; /usr/local/bin/nasm -f macho64 myLibraryExample.asm && gcc -arch x86_64 -o exampleAsm myLibraryExample.o myLibrary.o && ./exampleAsm
; ------------------------------------------------------------------------------

global _main
extern _foo

section .text
_main:
sub rsp, 8

lea rdi, [message] ; Use this instead of 'mov rdi, message'
call _foo
add rsp, 8
ret

section .data
message:
default rel ; Add 'default rel' under label
db "Hola, mundo",0
15 changes: 15 additions & 0 deletions asm/Calling My C Library From Assembly/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

To Compile the library:
gcc -c myLibrary.c -o myLibrary.o

To Compile the C Example
gcc -c myLibraryExample.c -o example.o

To Link the C Example
gcc example.o myLibrary.o -o example

To Run the C Example
./example

To Compile the Asm Example
/usr/local/bin/nasm -f macho64 myLibraryExample.asm && gcc -arch x86_64 -o exampleAsm myLibraryExample.o myLibrary.o && ./exampleAsm
Binary file added asm/Hello World In Assembly/hello
Binary file not shown.
Binary file added asm/Hello World In Assembly/hola
Binary file not shown.
24 changes: 24 additions & 0 deletions asm/Hello World In Assembly/hola.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; ------------------------------------------------------------------------------
; Writes "Hola, mundo" to the console using a C library. Runs on Linux or any
; other system that does not use underscores for symbols in its C library. To
; assemble and run:
;
; /usr/local/bin/nasm -f macho64 hola.asm && gcc -arch x86_64 -o hola hola.o && ./hola
; ------------------------------------------------------------------------------

global _main
extern _puts

section .text
_main:
sub rsp, 8

lea rdi, [message] ; Use this instead of 'mov rdi, message'
call _puts
add rsp, 8
ret

section .data
message:
default rel ; Add 'default rel' under label
db "Hola, mundo",0
Binary file added asm/Hello World In Assembly/hola.o
Binary file not shown.
14 changes: 14 additions & 0 deletions asm/Hello World In Assembly/hw.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
global start
section .text
start:
mov rax, 0x2000004 ; write
mov rdi, 1 ; stdout
mov rsi, msg
mov rdx, msg.len
syscall
mov rax, 0x2000001 ; exit
mov rdi, 0
syscall
section .data
msg: db "Hello, world!", 10
.len: equ $ - msg
Binary file added asm/Hello World In Assembly/hw.o
Binary file not shown.
Binary file added asm/Hello World In Assembly/hw2
Binary file not shown.
21 changes: 21 additions & 0 deletions asm/Hello World In Assembly/hw2.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; --------------------------------------------------------
; nasm -f macho64 hw2.asm && gcc -arch x86_64 -o hw2 hw2.o && ./hw2
; --------------------------------------------------------


global _main
extern _puts

section .text
_main:
sub rsp, 8
lea rdi, [message] ; use lea instead of mov rdi
call _puts
add rsp, 8
ret
section .data
message:
default rel ; put under label when referencing labeled memory
db "Hola, mundo",0
Binary file added asm/Hello World In Assembly/hw2.o
Binary file not shown.
Loading

0 comments on commit 8e6105d

Please sign in to comment.