- %include "../include/io.mac"
- extern printf
- global base64
- section .data
- alphabet db 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
- fmt db "%d", 10, 0
- section .text
- base64:
- ;; DO NOT MODIFY
- push ebp
- mov ebp, esp
- pusha
- mov esi, [ebp + 8] ; source array
- mov ebx, [ebp + 12] ; n
- mov edi, [ebp + 16] ; dest array
- mov edx, [ebp + 20] ; pointer to dest length
- ;; DO NOT MODIFY
- ; -- Your code starts here --
- xor ecx, ecx
- loop:
- mov ebx, [ebp + 12]
- cmp ecx, ebx
- jge gata
- ;; iau fiecare caracter si traduc octetul lu i in binar
- tradu_char:
- mov al, [esi + ecx]
- xor ebx, ebx
- mov ebx, 8
- loop_tradus:
- cmp ebx, 0
- jle tradus
- shl al, 1 ; esi:Man edi: 101010101010101010101010
- jc pune_unu
- mov byte [edi], '0'
- jmp repeta
- pune_unu:
- mov byte [edi], '1'
- repeta:
- inc edi
- dec ebx
- jmp loop_tradus
- tradus:
- inc ecx
- jmp loop
- ;; acum in edi este un sir de 1 si 0
- ;; acest sir reprezinta sirul esi in binar
- ;; parcurg sirul de 1 si 0 si transform inapoi in caractere
- gata:
- mov ecx, edi ; ecx = pointer la sir binar
- xor edi, edi
- mov edi, [ebp + 16] ; resetezi edi la începutul dest
- mov ebx, [ebp + 12]
- jmp final
- mov eax, ebx
- imul eax, 8
- mov ebx, eax
- xor eax, eax ; număr total de biți abcd: a:10101010
- xor edx, edx
- loop_scriere:
- jmp final
- xor ah, ah ; valoare de 6 biți
- ;ecx: 101010 101010 101010 101010
- mov al, 6
- loop_biti:
- cmp al, 0
- jle convertit
- shl ah, 1 ; 0|00101010
- cmp byte [ecx], '1'
- jne zero
- or ah, 1
- zero:
- inc ecx
- dec al
- jmp loop_biti
- convertit:
- movzx eax, ah
- mov al, [alphabet + eax]
- mov [edi], al
- inc edi
- sub ebx, 6
- inc edx
- jmp loop_scriere
- final:
- mov ebx, [ebp + 12]
- mov esi, [ebp + 8]
- ; -- Your code ends here --
- ;; DO NOT MODIFY
- popa
- leave
- ret
- ;; DO NOT MODIFY
The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Assembly - Guest
6th May 2025 10:01:35 PM
TEXT
57 views
Raw Paste