diff --git a/laborator/content/rolul-registrelor-adresare/0-recap/power-2.asm b/laborator/content/rolul-registrelor-adresare/0-recap/power-2.asm index 41cd5b41..0aebbfba 100644 --- a/laborator/content/rolul-registrelor-adresare/0-recap/power-2.asm +++ b/laborator/content/rolul-registrelor-adresare/0-recap/power-2.asm @@ -9,8 +9,24 @@ main: mov eax, 211 ; to be broken down into powers of 2 mov ebx, 1 ; stores the current power + mov ecx, eax +shift: + shl ebx,1 + cmp ecx,1 + je done + cmp ecx,ebx + jl printit + jg shift - ; TODO - print the powers of 2 that generate number stored in EAX +printit: + shr ebx, 1 + PRINTF32 `%d \x0`, ebx + sub ecx,ebx + mov ebx,1 + jmp shift + ; TODO - print the powers of 2 that generate number stored in EAX +done: + PRINTF32 `%d \x0`, ecx leave ret diff --git a/laborator/content/rolul-registrelor-adresare/1-2-multiply/multiply.asm b/laborator/content/rolul-registrelor-adresare/1-2-multiply/multiply.asm index 6eb39fea..83fb421f 100644 --- a/laborator/content/rolul-registrelor-adresare/1-2-multiply/multiply.asm +++ b/laborator/content/rolul-registrelor-adresare/1-2-multiply/multiply.asm @@ -31,6 +31,10 @@ main: ; TODO: Implement multiplication for dw and dd data types. + PRINTF32 `%s\x0`, print_mesaj + xor ebx, ebx + mov bx, ax + PRINTF32 `%hx\n\x0`, eax leave ret diff --git a/laborator/content/rolul-registrelor-adresare/3-4-sum-n/sum-n b/laborator/content/rolul-registrelor-adresare/3-4-sum-n/sum-n new file mode 100755 index 00000000..b151d5ef Binary files /dev/null and b/laborator/content/rolul-registrelor-adresare/3-4-sum-n/sum-n differ diff --git a/laborator/content/rolul-registrelor-adresare/3-4-sum-n/sum-n.asm b/laborator/content/rolul-registrelor-adresare/3-4-sum-n/sum-n.asm index f80ce5ee..dc3b62b5 100644 --- a/laborator/content/rolul-registrelor-adresare/3-4-sum-n/sum-n.asm +++ b/laborator/content/rolul-registrelor-adresare/3-4-sum-n/sum-n.asm @@ -1,29 +1,30 @@ %include "../utils/printf32.asm" -section .data +section.data: num dd 100 print_format1 db "Sum(", 0 - print_format2 db "): ", 0 + print_format2 db "):", 0 -section .text +section.text: extern printf global main main: - push ebp - mov ebp, esp - - mov ecx, [num] ; Use ecx as counter for computing the sum. - xor eax, eax ; Use eax to store the sum. Start from 0. +push ebp +mov ebp, esp +mov ecx,[num] ; Use ecx as counter for computing the sum. +xor ebx, ebx ; Use ax to store the sum. Start from 0. add_to_sum: - add eax, ecx - loop add_to_sum ; Decrement ecx. If not zero, add it to sum. +mov eax, ecx +mul eax +add ebx, eax +loop add_to_sum ;Decrement ex. If not zero, add it to sum. - mov ecx, [num] - PRINTF32 `%s\x0`, print_format1 - PRINTF32 `%u\x0`, ecx - PRINTF32 `%s\x0`, print_format2 - PRINTF32 `%u\n\x0`, eax +mov ecx, [num] +PRINTF32`%5\x0`, print_format1 +PRINTF32`%u\x0`, ecx +PRINTF32`%s\x0`, print_format2 +PRINTF32`%u\n\x0`, ebx - leave - ret +leave +ret diff --git a/laborator/content/rolul-registrelor-adresare/5-6-7-sum-array/sum-array b/laborator/content/rolul-registrelor-adresare/5-6-7-sum-array/sum-array new file mode 100755 index 00000000..a246ac20 Binary files /dev/null and b/laborator/content/rolul-registrelor-adresare/5-6-7-sum-array/sum-array differ diff --git a/laborator/content/rolul-registrelor-adresare/5-6-7-sum-array/sum-array.asm b/laborator/content/rolul-registrelor-adresare/5-6-7-sum-array/sum-array.asm index 0a398af3..060b20a5 100644 --- a/laborator/content/rolul-registrelor-adresare/5-6-7-sum-array/sum-array.asm +++ b/laborator/content/rolul-registrelor-adresare/5-6-7-sum-array/sum-array.asm @@ -16,16 +16,19 @@ main: mov ebp, esp mov ecx, ARRAY_SIZE ; Use ecx as loop counter. + xor eax, eax ; Use eax to store the sum. xor edx, edx ; Store current value in dl; zero entire edx. + xor ebx, ebx add_byte_array_element: - mov dl, byte [byte_array + ecx - 1] - add eax, edx + mov al, byte [byte_array + ecx - 1] + mul al + add ebx, eax loop add_byte_array_element ; Decrement ecx, if not zero, add another element. PRINTF32 `%s\x0`, print_format - PRINTF32 `%u\n\x0`, eax + PRINTF32 `%u\n\x0`, ebx ; TODO: Compute sum for elements in word_array and dword_array. diff --git a/laborator/content/rolul-registrelor-adresare/8-divide/divide.asm b/laborator/content/rolul-registrelor-adresare/8-divide/divide.asm index 763adfdc..34581a19 100644 --- a/laborator/content/rolul-registrelor-adresare/8-divide/divide.asm +++ b/laborator/content/rolul-registrelor-adresare/8-divide/divide.asm @@ -36,8 +36,36 @@ main: ; TODO: Calculate quotient and remainder for 67254 / 1349. + mov ax, word [dividend2] + mov dx, word [dividend2] + shr dx, 8 + mov bx, word [divisor2] + div bx + + PRINTF32 `%s\x0`,string_quotient + xor ebx, ebx + mov dx, ax + PRINTF32 `%hhu\n\x0`, ebx + xor ebx, ebx + mov bx, dx + PRINTF32 `%s\x0`,string_remainder + PRINTF32 ` %hhu\n\x0`, ebx ; TODO: Calculate quotient and remainder for 69094148 / 87621. + mov eax, dword [dividend3] + mov edx, dword [dividend3] + shr edx, 16 + mov ebx, dword [divisor3] + div ebx + PRINTF32 `%s\x0`, string_quotient + xor ebx, ebx + mov ebx, eax + PRINTF32 `%hhu\n\x0`, ebx + xor ebx, ebx + mov ebx, edx + PRINTF32 `%s\x0`, string_remainder + PRINTF32 `%hhu\n\x0`, ebx + leave ret