Desafio das aulas ao vivo 7 e 8 #8

Open
opened 2025-07-16 09:41:46 -03:00 by blau_araujo · 0 comments
Owner
%define EOL 0x0a

section .bss
	buf_argc resq 1		 ; 8 bytes inicializados com 0x00

section .text
global _start
_start:

	xor rcx, rcx		 ; rcx (contador) = 0
	mov rax, [rsp]		 ; rax = valor de ARGC

	; Imprimir a quantidade de argumentos com quebra de linha...
	call print_argc
	
args_loop:
	inc rcx			 ; incrementa contador
	lea rax, [rsp + 8 * rcx] ; avança 8*contador na pilha
	mov rbx, [rax]		 ; endereço de ARGV[rcx - 1]
	test rbx, rbx		 ; testa se endereço é NULL
	jz _exit		 ; se for, termina

	; Imprimir a string do argumento com quebra de linha...
	call print_args
	
	jmp args_loop
	
_exit:
	mov rax, 60
	xor rdi, rdi
	syscall

; ----------------------------------------------------------
; print_argc: Imprime a quantidade de argumentos com \n...
; ----------------------------------------------------------
print_argc:
; ----------------------------------------------------------
; rdi => ARGC
; ----------------------------------------------------------


	ret
; ----------------------------------------------------------
; print_args: Imprme a string do argumento com \n...
; ----------------------------------------------------------
print_args:
; ----------------------------------------------------------
; rsi => *BUF
; rdx => SIZE
; ----------------------------------------------------------


	ret
; ----------------------------------------------------------
; Syscall write (altera RCX e R11)
; ----------------------------------------------------------
; mov rax, SYS_WRITE (1)
; mov rdi, FD (1 = STDOUT)
; mov rsi, *BUF
; mov rdx, SIZE
; syscall
; ----------------------------------------------------------
```asm %define EOL 0x0a section .bss buf_argc resq 1 ; 8 bytes inicializados com 0x00 section .text global _start _start: xor rcx, rcx ; rcx (contador) = 0 mov rax, [rsp] ; rax = valor de ARGC ; Imprimir a quantidade de argumentos com quebra de linha... call print_argc args_loop: inc rcx ; incrementa contador lea rax, [rsp + 8 * rcx] ; avança 8*contador na pilha mov rbx, [rax] ; endereço de ARGV[rcx - 1] test rbx, rbx ; testa se endereço é NULL jz _exit ; se for, termina ; Imprimir a string do argumento com quebra de linha... call print_args jmp args_loop _exit: mov rax, 60 xor rdi, rdi syscall ; ---------------------------------------------------------- ; print_argc: Imprime a quantidade de argumentos com \n... ; ---------------------------------------------------------- print_argc: ; ---------------------------------------------------------- ; rdi => ARGC ; ---------------------------------------------------------- ret ; ---------------------------------------------------------- ; print_args: Imprme a string do argumento com \n... ; ---------------------------------------------------------- print_args: ; ---------------------------------------------------------- ; rsi => *BUF ; rdx => SIZE ; ---------------------------------------------------------- ret ; ---------------------------------------------------------- ; Syscall write (altera RCX e R11) ; ---------------------------------------------------------- ; mov rax, SYS_WRITE (1) ; mov rdi, FD (1 = STDOUT) ; mov rsi, *BUF ; mov rdx, SIZE ; syscall ; ---------------------------------------------------------- ```
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: blau_araujo/pbn#8
No description provided.