Created
January 16, 2025 10:34
-
-
Save thinkphp/fff90a94cd014d807d8bfe9f77df89f4 to your computer and use it in GitHub Desktop.
Cauta valoarea maxima absoluta intr-un vector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
section .data | |
vec DD -5, -7, 3, -17, 8, -2, 0 ; vector exemplu | |
section .text | |
global _start | |
_start: | |
xor ebx, ebx ; ebx = 0 (maxim curent) | |
mov esi, vec ; esi = adresa vectorrului | |
next: | |
mov eax, [esi] ; eax = elementul curent | |
cmp eax, 0 ; ne intrebam daca am ajuns la zero | |
je done ; dacă da, am terminat | |
; calculam valoarea absoluta | |
mov edx, eax ; save valoarea in EDX | |
test eax, eax ; check daca e negativ <0 | |
jns skip_neg ; dacă nu e negativ, jump | |
neg eax ; dacă e negativ, il negăm | |
skip_neg: | |
; comparam cu maximul current | |
cmp eax, ebx ; | |
jle not_greater ; dacă nu e mai mare, sarim peste | |
mov ebx, eax ; facem update la maximul | |
not_greater: | |
add esi, 4 ; trecem la urmatorul element | |
jmp next ; repetam pentru urmatorul element | |
done: | |
mov eax, ebx ; punem rezultatul în eax | |
; exit | |
mov ebx, eax ; save the result pentru exit | |
mov eax, 1 ; syscall exit | |
int 0x80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment