Last active
November 8, 2019 10:25
-
-
Save barbu110/e5b58a4c3f70d9d5291c583caddd2cf0 to your computer and use it in GitHub Desktop.
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
%include "io.inc" | |
%define ARRAY_SIZE 13 | |
%define DECIMAL_PLACES 5 | |
section .data | |
num_array dw 76, 12, 65, 19, 781, 671, 431, 761, 782, 12, 91, 25, 9 | |
array_sum_prefix db "Sum of numbers: ",0 | |
array_mean_prefix db "Numbers mean: ",0 | |
decimal_point db ".",0 | |
section .text | |
global CMAIN | |
CMAIN: | |
xor eax, eax | |
mov ecx, ARRAY_SIZE | |
add_element_to_sum: | |
add ax, [num_array + 2 * ecx - 2] | |
loop add_element_to_sum | |
PRINT_STRING array_sum_prefix | |
PRINT_UDEC 2, ax | |
NEWLINE | |
xor dx, dx | |
mov cx, ARRAY_SIZE | |
div cx | |
PRINT_STRING array_mean_prefix | |
PRINT_UDEC 2, ax | |
PRINT_STRING decimal_point | |
xor eax, eax | |
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
%include "io.inc" | |
section .text | |
global CMAIN | |
CMAIN: | |
mov ebp, esp; for correct debugging | |
; cele doua numere se gasesc in eax si ebx | |
mov eax, 15 | |
mov ebx, 4 | |
; TODO: aflati maximul folosind doar o instructiune de salt si push/pop | |
cmp eax, ebx | |
push eax | |
jg print | |
push ebx | |
print: | |
pop eax | |
PRINT_DEC 4, eax ; afiseaza maximul | |
NEWLINE | |
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
%include "io.inc" | |
section .data | |
%define ARRAY_LEN 7 | |
input dd 122, 184, 199, 242, 263, 845, 911 | |
output times ARRAY_LEN dd 0 | |
section .text | |
global CMAIN | |
CMAIN: | |
mov ebp, esp; for correct debugging | |
; TODO push the elements of the array on the stack | |
; TODO retrieve the elements (pop) from the stack into the output array | |
xor ecx, ecx | |
add_to_stack: | |
push dword [input + 4 * ecx] | |
inc ecx | |
cmp ecx, ARRAY_LEN | |
jb add_to_stack | |
xor ecx, ecx | |
add_to_output: | |
pop dword [output + 4 * ecx] | |
inc ecx | |
cmp ecx, ARRAY_LEN | |
jb add_to_output | |
start_print: | |
PRINT_STRING "Reversed array:" | |
NEWLINE | |
xor ecx, ecx | |
print_array: | |
PRINT_UDEC 4, [output + 4 * ecx] | |
NEWLINE | |
inc ecx | |
cmp ecx, ARRAY_LEN | |
jb print_array | |
xor eax, eax | |
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
%include "io.inc" | |
%define NUM 5 | |
section .text | |
global CMAIN | |
CMAIN: | |
mov ebp, esp | |
; TODO 1: replace every push by an equivalent sequence of commands | |
; pushing an array on the stack | |
mov ecx, NUM | |
push_nums: | |
push ecx | |
loop push_nums | |
; pushing a string on the stack | |
sub esp, 1 | |
mov [esp], byte 0 | |
sub esp, 4 | |
mov [esp], dword "mere" | |
sub esp, 4 | |
mov [esp], dword "are " | |
sub esp, 4 | |
mov [esp], dword "Ana " | |
; TODO 2: print the stack in "address: value" format in the range of [ESP:EBP] | |
; (from low addresses to high addresses, byte by byte) | |
mov ecx, esp | |
print_stack_byte: | |
PRINT_UDEC 1, [ecx] | |
NEWLINE | |
inc ecx | |
cmp ecx, ebp | |
jb print_stack_byte | |
; TODO 3: print the string byte by byte | |
; TODO 4: print the array element by element | |
; restore the previous value of the EBP (Base Pointer) | |
mov esp, ebp | |
; exit without errors | |
xor eax, eax | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment