Skip to content

Commit

Permalink
Add demos for lab08.
Browse files Browse the repository at this point in the history
Add demos for lab08.
Signed-off-by: Gabriel Mocanu <[email protected]>
  • Loading branch information
gabrielmocanu committed Mar 30, 2024
1 parent 6f4139d commit 8068505
Show file tree
Hide file tree
Showing 20 changed files with 163 additions and 119 deletions.
2 changes: 1 addition & 1 deletion laborator/content/stiva/0-mean/mean.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%include "../utils/printf32.asm"
%include "printf32.asm"

%define ARRAY_SIZE 13
%define DECIMAL_PLACES 5
Expand Down
2 changes: 1 addition & 1 deletion laborator/content/stiva/1-max/max.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%include "../utils/printf32.asm"
%include "printf32.asm"

section .text

Expand Down
2 changes: 1 addition & 1 deletion laborator/content/stiva/2-reverse/reverse-array.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%include "../utils/printf32.asm"
%include "printf32.asm"

%define ARRAY_LEN 7

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%include "../utils/printf32.asm"
%include "printf32.asm"

%define NUM 5
Expand Down
2 changes: 1 addition & 1 deletion laborator/content/stiva/4-local-var/merge-arrays.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%include "../utils/printf32.asm"
%include "printf32.asm"

%define ARRAY_1_LEN 5
%define ARRAY_2_LEN 7
Expand Down
2 changes: 1 addition & 1 deletion laborator/content/stiva/5-gcd/gcd.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%include "../utils/printf32.asm"
%include "printf32.asm"

section .text

Expand Down
2 changes: 2 additions & 0 deletions laborator/content/stiva/demo/stack-addressing/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PROGNAME := stack-addressing
include ../../../utils/Makefile.generic
29 changes: 29 additions & 0 deletions laborator/content/stiva/demo/stack-addressing/stack-addressing.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
%include "printf32.asm"

section .text

extern printf
global main
main:
push ebp
mov ebp, esp

push dword 10
push dword 11
push dword 12
push dword 13

mov eax, ebp
print_stack:
PRINTF32 `0x\x0`
PRINTF32 `%x\x0`, eax
PRINTF32 `: 0x\x0`
PRINTF32 `%x\n\x0`, [eax]

sub eax, 4
cmp eax, esp
jge print_stack

xor eax, eax
leave
ret
2 changes: 2 additions & 0 deletions laborator/content/stiva/demo/stack-operations/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PROGNAME := stack-operations
include ../../../utils/Makefile.generic
45 changes: 45 additions & 0 deletions laborator/content/stiva/demo/stack-operations/stack-operations.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
%include "printf32.asm"

section .text

; esp -> stack pointer
; ebp -> base pointer

extern printf
global main
main:
push ebp
mov ebp, esp

push dword 10 ; sub esp, 4; mov [esp], 10;
push dword 11 ; sub esp, 4; mov [esp], 11;
push dword 12 ; sub esp, 4; mov [esp], 12;
push dword 13 ; sub esp, 4; mov [esp], 13;
push dword 14 ; sub esp, 4; mov [esp], 13;


pusha ; push all registers on the stack
popa ; pop all registers from the stack

; Version 1
pop eax; ; mov eax, [esp]; add esp, 4
pop eax; ; mov eax, [esp]; add esp, 4
pop eax; ; mov eax, [esp]; add esp, 4
pop eax; ; mov eax, [esp]; add esp, 4
pop eax; ; mov eax, [esp]; add esp, 4

; Version 2
; add esp, 20 ; 4 * number_of_push

; Version 3
; mov esp, ebp

; sub esp <-> add esp -> use to allocate/deallocate memory

; Aloc 8 bytes <-> 2 int
; sub esp, 8
; mov [esp], 10
; mov [esp + 4], 12

leave
ret
3 changes: 0 additions & 3 deletions laborator/content/stiva/demo/sum-n/.gitignore

This file was deleted.

21 changes: 2 additions & 19 deletions laborator/content/stiva/demo/sum-n/Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,2 @@
NASM = nasm
AFILES = sum_n_init.asm sum_n_interm.asm sum_n.asm
OBJS = $(AFILES:.asm=.o)
ASM_FLAGS = -f elf32 -g
LD=gcc
LDFLAGS = -m32 -g
BINARIES = $(OBJS:.o=)

all: $(BINARIES)

%.o: %.asm
$(NASM) $(ASM_FLAGS) -o $@ $<

mean: mean.o
$(LD) $(LDFLAGS) -o $@ $^

clean:
rm -f *.o $(BINARIES) *.s
rm -f *~
PROGNAME := sum_n
include ../../../utils/Makefile.generic
30 changes: 15 additions & 15 deletions laborator/content/stiva/demo/sum-n/sum_n.asm
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
%include "../utils/printf32.asm"
%include "printf32.asm"

section .text
extern printf
global main

main:
push ebp
mov ebp, esp
push ebp
mov ebp, esp

; ecx <- i (number / increment)
; eax <- sum
; init i (i <- 100)
mov ecx, 100
; init sum (sum <- 0)
xor eax, eax ; mov eax, 0
; ecx <- i (number / increment)
; eax <- sum
; init i (i <- 100)
mov ecx, 100
; init sum (sum <- 0)
xor eax, eax ; mov eax, 0

.L3:
add eax, ecx
loop .L3 ; dec ecx; cmp ecx, 0; jne .L3
add eax, ecx
loop .L3 ; dec ecx; cmp ecx, 0; jne .L3

PRINTF32 `%u\n\x0`, eax
mov eax, 0
pop ebp
ret
PRINTF32 `%u\n\x0`, eax
mov eax, 0
pop ebp
ret
32 changes: 0 additions & 32 deletions laborator/content/stiva/demo/sum-n/sum_n_init.asm

This file was deleted.

26 changes: 0 additions & 26 deletions laborator/content/stiva/demo/sum-n/sum_n_interm.asm

This file was deleted.

2 changes: 2 additions & 0 deletions laborator/content/stiva/demo/sum_n_init/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PROGNAME := sum_n_init
include ../../../utils/Makefile.generic
32 changes: 32 additions & 0 deletions laborator/content/stiva/demo/sum_n_init/sum_n_init.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
%include "printf32.asm"

section .data
i: dd 0
sum: dd 0

section .text
extern printf
global main

main:
push ebp
mov ebp, esp
mov dword [i], 1
.L3:
mov eax, [i]
cmp eax, 100
ja .L2
mov edx, [sum]
mov eax, [i]
add eax, edx
mov [sum], eax
; mov eax, [i]
; add eax, 1
; mov [i], eax
inc dword [i]
jmp .L3
.L2:
PRINTF32 `%u\n\x0`, dword [sum]
mov eax, 0
pop ebp
ret
2 changes: 2 additions & 0 deletions laborator/content/stiva/demo/sum_n_interm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PROGNAME := sum_n_interm
include ../../../utils/Makefile.generic
26 changes: 26 additions & 0 deletions laborator/content/stiva/demo/sum_n_interm/sum_n_interm.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
%include "printf32.asm"

section .data
i: dd 0
sum: dd 0

section .text
extern printf
global main

main:
push ebp
mov ebp, esp
mov dword [i], 1
.L3:
mov eax, [i]
cmp eax, 100
ja .L2
add [sum], eax
inc dword [i]
jmp .L3
.L2:
PRINTF32 `%u\n\x0`, dword [sum]
mov eax, 0
pop ebp
ret
18 changes: 0 additions & 18 deletions laborator/content/stiva/utils/printf32.asm

This file was deleted.

0 comments on commit 8068505

Please sign in to comment.