-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add demos for lab08. Signed-off-by: Gabriel Mocanu <[email protected]>
- Loading branch information
1 parent
6f4139d
commit 8068505
Showing
20 changed files
with
163 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
%include "../utils/printf32.asm" | ||
%include "printf32.asm" | ||
|
||
section .text | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
laborator/content/stiva/3-stack-addressing/stack-addressing.asm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
%include "../utils/printf32.asm" | ||
%include "printf32.asm" | ||
|
||
%define NUM 5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
%include "../utils/printf32.asm" | ||
%include "printf32.asm" | ||
|
||
section .text | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
laborator/content/stiva/demo/stack-addressing/stack-addressing.asm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
45
laborator/content/stiva/demo/stack-operations/stack-operations.asm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
PROGNAME := sum_n_init | ||
include ../../../utils/Makefile.generic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
laborator/content/stiva/demo/sum_n_interm/sum_n_interm.asm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.