first
This commit is contained in:
BIN
add_and_subtract
Executable file
BIN
add_and_subtract
Executable file
Binary file not shown.
26
add_and_subtract.hla
Normal file
26
add_and_subtract.hla
Normal file
@@ -0,0 +1,26 @@
|
||||
program AddAndSub;
|
||||
|
||||
#include("stdlib.hhf")
|
||||
|
||||
static
|
||||
eight_bit_integer: int8 := 7;
|
||||
|
||||
begin AddAndSub;
|
||||
|
||||
stdout.put
|
||||
(
|
||||
nl,
|
||||
"Initialized values: eight_bit_integer=",
|
||||
eight_bit_integer,
|
||||
nl
|
||||
);
|
||||
|
||||
mov( 0, dh ); // `al` is an eight-bit register
|
||||
sub( eight_bit_integer, dh ); // `al` minus `eight_bit_integer`
|
||||
mov( dh, eight_bit_integer ); // this should be -7
|
||||
|
||||
stdout.put(nl, "Now eight_bit_integer = ", eight_bit_integer, nl);
|
||||
// add( 135, eight_bit_integer);
|
||||
// stdout.put(nl, "Now eight_bit_integer = ", eight_bit_integer, nl);
|
||||
|
||||
end AddAndSub;
|
||||
BIN
add_and_subtract.o
Normal file
BIN
add_and_subtract.o
Normal file
Binary file not shown.
12
dec.hla
Normal file
12
dec.hla
Normal file
@@ -0,0 +1,12 @@
|
||||
program ConvertToDecimal;
|
||||
#include("stdlib.hhf")
|
||||
static
|
||||
value: int32;
|
||||
|
||||
begin ConvertToDecimal;
|
||||
|
||||
stdout.put("Input a hex value: ");
|
||||
stdin.get(eax);
|
||||
mov(eax, value);
|
||||
stdout.put("The value $", eax, " converted to decimal is ", value, nl);
|
||||
end ConvertToDecimal;
|
||||
BIN
fasm_with_tsoding/.server.asm.swp
Normal file
BIN
fasm_with_tsoding/.server.asm.swp
Normal file
Binary file not shown.
BIN
fasm_with_tsoding/.steps.md.swp
Normal file
BIN
fasm_with_tsoding/.steps.md.swp
Normal file
Binary file not shown.
BIN
fasm_with_tsoding/hello
Executable file
BIN
fasm_with_tsoding/hello
Executable file
Binary file not shown.
34
fasm_with_tsoding/hello.asm
Normal file
34
fasm_with_tsoding/hello.asm
Normal file
@@ -0,0 +1,34 @@
|
||||
format ELF64 executable
|
||||
|
||||
STDOUT = 1
|
||||
HAPPY_EXIT_CODE = 1
|
||||
SYSCALL_EXIT = 60
|
||||
SYSCALL_WRITE = 1
|
||||
|
||||
macro print fd, buf, len
|
||||
{
|
||||
mov rax, SYSCALL_WRITE ; 1 -> write, which takes three arguments (below)
|
||||
mov rdi, fd
|
||||
mov rsi, buf
|
||||
mov rdx, len
|
||||
syscall
|
||||
}
|
||||
|
||||
macro exit code
|
||||
{
|
||||
mov rax, SYSCALL_EXIT
|
||||
mov rdi, HAPPY_EXIT_CODE
|
||||
syscall
|
||||
}
|
||||
|
||||
segment readable executable
|
||||
entry main
|
||||
main:
|
||||
print STDOUT, msg, msg_len
|
||||
exit 1
|
||||
|
||||
|
||||
segment readable writeable
|
||||
msg db "Hello, World!", 10
|
||||
msg_len db $ - msg
|
||||
|
||||
BIN
fasm_with_tsoding/server
Executable file
BIN
fasm_with_tsoding/server
Executable file
Binary file not shown.
49
fasm_with_tsoding/server.asm
Normal file
49
fasm_with_tsoding/server.asm
Normal file
@@ -0,0 +1,49 @@
|
||||
format ELF64 executable
|
||||
|
||||
STDOUT = 1
|
||||
HAPPY_EXIT_CODE = 0
|
||||
SYSCALL_EXIT = 60
|
||||
SYSCALL_WRITE = 1
|
||||
SYSCALL_SOCKET = 41
|
||||
AF_INET = 2
|
||||
SOCK_STREAM = 1
|
||||
|
||||
macro print buf, len
|
||||
{
|
||||
mov rax, SYSCALL_WRITE ; 1 -> write, which takes three arguments (below)
|
||||
mov rdi, STDOUT
|
||||
mov rsi, buf
|
||||
mov rdx, len
|
||||
syscall
|
||||
}
|
||||
|
||||
macro exit code
|
||||
{
|
||||
mov rax, SYSCALL_EXIT
|
||||
mov rdi, code
|
||||
syscall
|
||||
}
|
||||
|
||||
macro socket domain, type, protocol
|
||||
{
|
||||
mov rax, SYSCALL_SOCKET
|
||||
mov rdi, domain
|
||||
mov rsi, type
|
||||
mov rdx, protocol
|
||||
syscall
|
||||
}
|
||||
|
||||
segment readable executable
|
||||
entry main
|
||||
main:
|
||||
print msg, msg_len
|
||||
socket AF_INET, SOCK_STREAM, 0
|
||||
mov dword [socket_fd], eax
|
||||
print [socket_fd], 32
|
||||
exit HAPPY_EXIT_CODE
|
||||
|
||||
|
||||
segment readable writeable
|
||||
msg db "Starting web server!", 10
|
||||
msg_len db $ - msg
|
||||
socket_fd dd 0
|
||||
10
fasm_with_tsoding/steps.md
Normal file
10
fasm_with_tsoding/steps.md
Normal file
@@ -0,0 +1,10 @@
|
||||
1) install fasm ([link](https://flatassembler.net/download.php))
|
||||
```bash
|
||||
sudo apt install build-essential manpages-dev software-properties-common
|
||||
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
|
||||
sudo apt update && sudo apt install gcc-11 g++-11
|
||||
```
|
||||
1) `sudo apt install libx11-dev`
|
||||
1) install gdb
|
||||
1) install [gf](git clone https://github.com/nakst/gf.git)
|
||||
|
||||
8
hello.hla
Normal file
8
hello.hla
Normal file
@@ -0,0 +1,8 @@
|
||||
program helloWorld;
|
||||
#include( "stdlib.hhf" );
|
||||
|
||||
begin helloWorld;
|
||||
|
||||
stdout.put( "Hello, World of Assembly Language" nl );
|
||||
|
||||
end helloWorld;
|
||||
12
hex.hla
Normal file
12
hex.hla
Normal file
@@ -0,0 +1,12 @@
|
||||
program ConvertToHex;
|
||||
#include("stdlib.hhf")
|
||||
static
|
||||
value: int32;
|
||||
|
||||
begin ConvertToHex;
|
||||
|
||||
stdout.put("Input a decimal value: ");
|
||||
stdin.get(value);
|
||||
mov(value, eax);
|
||||
stdout.put("The value ", value, " converted to hex is $", eax, nl);
|
||||
end ConvertToHex;
|
||||
BIN
logical_ops
Executable file
BIN
logical_ops
Executable file
Binary file not shown.
13
logical_ops.hla
Normal file
13
logical_ops.hla
Normal file
@@ -0,0 +1,13 @@
|
||||
program LogicalOp;
|
||||
#include("stdlib.hhf")
|
||||
begin LogicalOp;
|
||||
stdout.put( "Input left operand: "); // 5 -> 0000_0000_0000_0101
|
||||
stdin.get( eax );
|
||||
stdout.put( "Input right operand: ");
|
||||
stdin.get( ebx ); // 15 -> 0000_0000_0000_1111
|
||||
|
||||
stdout.put( "$", eax, " xor $", ebx, " = $");
|
||||
// mov (eax, ecx );
|
||||
xor (eax, ebx );
|
||||
stdout.put( ebx, nl); // 10
|
||||
end LogicalOp;
|
||||
BIN
logical_ops.o
Normal file
BIN
logical_ops.o
Normal file
Binary file not shown.
20
sign_extension.hla
Normal file
20
sign_extension.hla
Normal file
@@ -0,0 +1,20 @@
|
||||
program signExtension;
|
||||
#include( "stdlib.hhf" )
|
||||
|
||||
static
|
||||
i8: int8;
|
||||
i16: int16;
|
||||
i32: int32;
|
||||
|
||||
begin signExtension;
|
||||
|
||||
stdout.put("Enter a small negative number: ");
|
||||
stdin.get(i8);
|
||||
stdout.put(nl, "Sign extension using CBW and CWDE:", nl, nl);
|
||||
|
||||
mov(i8, al);
|
||||
stdout.put("You entered ", i8, " ($", al, ")", nl);
|
||||
|
||||
cbw(); // ??? must be sign extending the value in `al` to `ax`
|
||||
mov(ax, i16);
|
||||
stdout.put("16-bit sign extension: ", i16, " ($", ax, ")", nl);
|
||||
BIN
twos_complement
Executable file
BIN
twos_complement
Executable file
Binary file not shown.
25
twos_complement.hla
Normal file
25
twos_complement.hla
Normal file
@@ -0,0 +1,25 @@
|
||||
program twosComplement;
|
||||
#include("stdlib.hhf")
|
||||
|
||||
static
|
||||
pos_value: int8;
|
||||
neg_value: int8;
|
||||
|
||||
begin twosComplement;
|
||||
|
||||
stdout.put( "Enter an integer between 0 and 127: " );
|
||||
stdin.get( pos_value );
|
||||
stdout.put( nl, "Value in hex: $" );
|
||||
stdout.puth8( pos_value );
|
||||
|
||||
mov( pos_value, al );
|
||||
// not ( al );
|
||||
// stdout.put( nl, "Invert all the bits: $", al, nl);
|
||||
// add( 1, al );
|
||||
neg( al );
|
||||
// stdout.put( "Add one: $", al, nl );
|
||||
mov( al, neg_value );
|
||||
stdout.put( nl, "Result in decimal: ", neg_value, nl);
|
||||
|
||||
end twosComplement;
|
||||
|
||||
BIN
twos_complement.o
Normal file
BIN
twos_complement.o
Normal file
Binary file not shown.
15
variables.hla
Normal file
15
variables.hla
Normal file
@@ -0,0 +1,15 @@
|
||||
program Vars;
|
||||
#include( "stdlib.hhf" )
|
||||
|
||||
static
|
||||
MyNum: int8 := 42;
|
||||
NumNotInitialized: int8;
|
||||
|
||||
begin Vars;
|
||||
|
||||
stdout.put( "MyNum = ", MyNum, nl);
|
||||
stdout.put( "Enter an integer value: " );
|
||||
stdin.get(NumNotInitialized);
|
||||
stdout.put( "You entered '", NumNotInitialized, "'", nl );
|
||||
|
||||
end Vars;
|
||||
BIN
variables.o
Normal file
BIN
variables.o
Normal file
Binary file not shown.
BIN
zero_extension
Executable file
BIN
zero_extension
Executable file
Binary file not shown.
14
zero_extension.hla
Normal file
14
zero_extension.hla
Normal file
@@ -0,0 +1,14 @@
|
||||
program zero_extension;
|
||||
#include("stdlib.hhf")
|
||||
|
||||
static
|
||||
magic_num: int8 := 42;
|
||||
magic_num_16: int16;
|
||||
|
||||
begin zero_extension;
|
||||
mov(magic_num, al);
|
||||
mov(0, ah);
|
||||
mov(ax, magic_num_16);
|
||||
stdout.put("magic_num_16 = ", magic_num_16); // should be 42
|
||||
end zero_extension;
|
||||
|
||||
BIN
zero_extension.o
Normal file
BIN
zero_extension.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user