Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion laborator/content/rolul-registrelor-adresare/0-recap/power-2.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file not shown.
35 changes: 18 additions & 17 deletions laborator/content/rolul-registrelor-adresare/3-4-sum-n/sum-n.asm
Original file line number Diff line number Diff line change
@@ -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
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 28 additions & 0 deletions laborator/content/rolul-registrelor-adresare/8-divide/divide.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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