section .data
NULL equ 0
EXIT_SUCCESS equ 0
SYS_exit equ 60
hit db "Hit! etiqueta is already filled", 0xA
hit_len equ $ - hit
miss db "Miss! etiqueta will be filled", 0xA
miss_len equ $ - miss
etiqueta_igual db "same etiqueta", 0xA
etiqueta_igual_len equ $ - etiqueta_igual
indice db 0b0000
masc_etiqueta dw 0b111111111000000
etiqueta dw 0, NULL
section .text
extern set_validation_bit
extern set_tag
extern get_data
extern display_table
extern get_validation_bit
extern get_tag
global _start
_start:
mov r12, rdi
cmp r12, 1
jl _Done
mov r13, rsi
mov rbx, 1
_vector_Arg_Loop_For:
;1.
movzx rsi, word [r13 + rbx * 8]
mov cx, word [rsi]
xchg cl, ch
mov dx, cx
and dx, [masc_etiqueta]
shr dx, 6
mov [etiqueta], dx
;2.
cmp dx, 0b0000000110000101 ; shr (aA and [masc_etiqueta]), 6 = 0b0000000110000101
jne _comp_etiquetas_e_set_tag
xor rax, rax
mov rax, 1
mov rdi, 1
mov rsi, etiqueta_igual
mov rdx, etiqueta_igual_len
syscall
_comp_etiquetas_e_set_tag:
;3.
movzx edi, byte[indice]
call get_tag
cmp rax, [etiqueta]
je _print_Hit
movzx edi, byte [indice]
movzx esi, word [etiqueta]
call set_tag
jmp _print_Miss
_print_Hit:
xor rax, rax
mov rax, 1
mov rdi, 1
mov rsi, hit
mov rdx, hit_len
syscall
jmp _vector_Arg_Loop_Ciclo
_print_Miss:
xor rax, rax
mov rax, 1
mov rdi, 1
mov rsi, miss
mov rdx, miss_len
syscall
_vector_Arg_Loop_Ciclo:
;4.
inc rbx
cmp rbx, r12
jl _vector_Arg_Loop_For
_Done:
mov rax, SYS_exit
mov rdi, EXIT_SUCCESS
syscall
- The code’s objective is to receive a certain number of arguments and process them one by one, swapping the letters, Aa -> aA, and using a mask to isolate the first 10 bits and then rotate them 6 bits to the right, making the most significant bit stay in the first 10 bits.
- After processing the argument, compare it with a word and if it is equal, print a warning string -> same etiqueta
- Then call the external function call get_tag which will return the last etiqueta via the rax register, if it exists, if the last etiqueta is equal to the current one, print -> Hit! tag is already filled, if not the etiqueta is updated by the current one with the external function set_tag and print -> Miss! tag will be filled
- After all this, start all over again with the next argument
what I received:
┌──(mattandmello㉿MattandMello)-[~/Desktop]
└─$ ./program Aa Bb Bb
zsh: segmentation fault ./program Aa Bb Bb
what was i waiting for:
┌──(mattandmello㉿MattandMello)-[~/Desktop]
└─$ ./validationBitSiml Aa Bb Bb
same etiqueta
Miss! etiqueta will be filled
Miss! etiqueta will be filled
Hit! etiqueta is already filled
biblioteca.o is were I have the external functions
$ nasm -f elf64 -g -F dwarf program.asm
$ gcc program.o biblioteca.o -o program -nostartfiles -fPIE -no-pie -lncurse
MattandMello is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2