diff --git a/laborator/content/stiva/0-mean/mean.asm b/laborator/content/stiva/0-mean/mean.asm index 00c3e18d..7643fa12 100644 --- a/laborator/content/stiva/0-mean/mean.asm +++ b/laborator/content/stiva/0-mean/mean.asm @@ -19,23 +19,44 @@ main: ; TODO1 - compute the sum of the vector numbers - store it in eax + sub ecx, 1 + +suma: + cmp ecx, 0 + jl out + add ax, word[num_array + ecx * 2] + sub ecx, 1 + jmp suma + +out: + PRINTF32 `Sum of numbers: %d\n\x0`, eax ; TODO2 - compute the quotient of the mean + xor edx, edx + + mov ebx, eax + mov ax, bx + shr ebx, 16 + mov dx, bx + mov cx, ARRAY_SIZE + div cx + PRINTF32 `Mean of numbers: %d\x0`, eax + xor eax, eax + ret PRINTF32 `.\x0` mov ecx, DECIMAL_PLACES + compute_decimal_place: ; TODO3 - compute the current decimal place - store it in ax - PRINTF32 `%d\x0`, eax dec ecx cmp ecx, 0 jg compute_decimal_place - PRINTF32 `\n\x0` xor eax, eax - ret + ret \ No newline at end of file diff --git a/laborator/content/stiva/1-max/max.asm b/laborator/content/stiva/1-max/max.asm index b814be93..d19dbe4e 100644 --- a/laborator/content/stiva/1-max/max.asm +++ b/laborator/content/stiva/1-max/max.asm @@ -9,8 +9,18 @@ main: mov eax, 1 mov ebx, 4 + mov ecx, eax + sub ecx, ebx + cmp ecx, 0 + jge out + push eax + push ebx + pop eax + pop ebx + ; TODO: get maximum value. You are only allowed to use one conditional jump and push/pop instructions. +out: PRINTF32 `Max value is: %d\n\x0`, eax ; print maximum value - ret + ret \ No newline at end of file diff --git a/laborator/content/stiva/2-reverse/reverse-array.asm b/laborator/content/stiva/2-reverse/reverse-array.asm index 711f9637..645da012 100644 --- a/laborator/content/stiva/2-reverse/reverse-array.asm +++ b/laborator/content/stiva/2-reverse/reverse-array.asm @@ -15,15 +15,41 @@ main: ; TODO push the elements of the array on the stack ; TODO retrieve the elements (pop) from the stack into the output array + mov ecx, ARRAY_LEN + sub ecx, 1 + +punem: + cmp ecx, 0 + jl out + push dword[input + ecx * 4] + sub ecx, 1 + jmp punem + +out: + ; TODO retrieve the elements (pop) from the stack into the output array + + xor ecx, ecx + mov ecx, ARRAY_LEN + sub ecx, 1 + +scoatem: + cmp ecx, 0 + jl gata + pop eax + mov dword[output + ecx * 4], eax + sub ecx, 1 + jmp scoatem + +gata: PRINTF32 `Reversed array: \n\x0` xor ecx, ecx + print_array: mov edx, [output + 4 * ecx] PRINTF32 `%d\n\x0`, edx inc ecx cmp ecx, ARRAY_LEN jb print_array - xor eax, eax ret diff --git a/laborator/content/stiva/3-stack-addressing/stack-addressing.asm b/laborator/content/stiva/3-stack-addressing/stack-addressing.asm index 0e0ed81b..7436aa55 100644 --- a/laborator/content/stiva/3-stack-addressing/stack-addressing.asm +++ b/laborator/content/stiva/3-stack-addressing/stack-addressing.asm @@ -13,26 +13,102 @@ main: mov ecx, NUM push_nums: push ecx + ;push ecx + sub esp, 4 + mov dword[esp], ecx loop push_nums push 0 push "mere" push "are " push "Ana " + ;push 0 + + sub esp, 4 + mov dword[esp], 0 + + ;push "mere" + sub esp, 4 + mov dword[esp], "mere" + + ;push "are " + sub esp, 4 + mov dword[esp], "are " + + ;push "Ana " + sub esp, 4 + mov dword[esp], "Ana " lea esi, [esp] PRINTF32 `%s\n\x0`, esi ; TODO 2: print the stack in "address: value" format in the range of [ESP:EBP] + + xor ebx, ebx + mov ebx, esp + + xor ecx, ecx + mov ecx, ebp + sub ecx, esp + +afisare: + cmp ecx, 0 + je out + PRINTF32 `%p \x0`, ebx + PRINTF32 `%hhu\n\x0`, byte[ebx] + add ebx, 1 + sub ecx, 1 + jmp afisare + ; use PRINTF32 macro - see format above +out: ; TODO 3: print the string + xor ebx, ebx + mov ebx, esp + + xor ecx, ecx + mov ecx, ebp + sub ecx, esp + +afisare_sir: + cmp ecx, 0 + je out_sir + xor eax, eax + mov al, byte[ebx] + cmp eax, 0 + je out_sir + PRINTF32 `%c\x0`, byte[ebx] + add ebx, 1 + sub ecx, 1 + jmp afisare_sir + + ; use PRINTF32 macro - see format above + +out_sir: + ; TODO 4: print the array on the stack, element by element. + add ebx, 4 + xor ecx, ecx + mov ecx, NUM + +PRINTF32 `\n\x0` + +afisare_vector: + cmp ecx, 0 + je out_vector + PRINTF32 `%hhu \x0`, byte[ebx] + add ebx, 4 + sub ecx, 1 + jmp afisare_vector + +out_vector: + ; restore the previous value of the EBP (Base Pointer) mov esp, ebp ; exit without errors xor eax, eax - ret + ret \ No newline at end of file diff --git a/laborator/content/stiva/4-local-var/merge-arrays.asm b/laborator/content/stiva/4-local-var/merge-arrays.asm index 776eaa34..4fca0a19 100644 --- a/laborator/content/stiva/4-local-var/merge-arrays.asm +++ b/laborator/content/stiva/4-local-var/merge-arrays.asm @@ -20,55 +20,122 @@ main: mov ebx, 0 ; counter used for array_2 mov ecx, 0 ; counter used for the output array + push ebp + mov ebp, esp + + sub esp, ARRAY_OUTPUT_LEN * 4 + merge_arrays: + xor edx, edx mov dl, byte [array_1 + eax] mov dh, byte [array_2 + ebx] cmp dl, dh jg array_2_lower + array_1_lower: mov byte [array_output + ecx], dl inc eax + ;mov byte [array_output + ecx], dl + + mov dword[esp + ecx * 4], 0 + mov byte[esp + ecx * 4], dl + inc ecx + inc eax jmp verify_array_end + array_2_lower: mov byte [array_output + ecx], dh + ;mov byte [array_output + ecx], dh + + mov dword[esp + ecx * 4], 0 + mov byte[esp + ecx * 4], dh + inc ecx inc ebx + jmp verify_array_end + verify_array_end: cmp eax, ARRAY_1_LEN jge copy_array_2 + je copy_array_2 cmp ebx, ARRAY_2_LEN jge copy_array_1 + je copy_array_1 jmp merge_arrays copy_array_1: + cmp eax, ARRAY_1_LEN + je print_array + + xor edx, edx mov dl, byte [array_1 + eax] mov byte [array_output + ecx], dl + + ;mov byte [array_output + ecx], dl + + mov dword[esp + ecx * 4], 0 + mov byte[esp + ecx * 4], dl + inc ecx inc eax cmp eax, ARRAY_1_LEN jb copy_array_1 jmp print_array + + jmp copy_array_1 + copy_array_2: + cmp ebx, ARRAY_2_LEN + je print_array + + xor edx, edx mov dh, byte [array_2 + ebx] mov byte [array_output + ecx], dh + + ;mov byte [array_output + ecx], dh + + mov dword[esp + ecx * 4], 0 + mov byte[esp + ecx * 4], dh + inc ecx inc ebx cmp ebx, ARRAY_2_LEN jb copy_array_2 + jmp copy_array_2 + print_array: PRINTF32 `Array merged:\n\x0` mov ecx, 0 + xor ecx, ecx + print: mov al, byte [array_output + ecx] + cmp ecx, ARRAY_OUTPUT_LEN + je out + + ;mov al, byte [array_output + ecx] + + xor eax, eax + mov eax, dword [esp + ecx * 4] + PRINTF32 `%d \x0`, eax + inc ecx cmp ecx, ARRAY_OUTPUT_LEN jb print + jmp print +out: PRINTF32 `\n\x0` + + add esp, ARRAY_OUTPUT_LEN * 4 + + mov esp, ebp + pop esp + xor eax, eax - ret - \ No newline at end of file + leave + ret \ No newline at end of file