Created
September 11, 2021 02:37
-
-
Save lucasgolino/50b83fb2cf96293f936abb01e1deec09 to your computer and use it in GitHub Desktop.
Leetcode find-the-difference
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 .text | |
global _start | |
_start: | |
mov esi, 0 ; initializer counter | |
jmp _loop | |
_loop: | |
cmp esi, s_len | |
je _print_diff ; prevent overflow s string size | |
mov al, [s + esi] ; get s[esi] | |
mov bl, [t + esi] ; get t[esi] | |
cmp al, bl ; compare eax == ebx | |
je _increment_to_loop ; jump equal to _increment_to_loop | |
; else | |
jmp _print_diff ; jump to _print_diff | |
_increment_to_loop: | |
inc esi | |
jmp _loop | |
_print_diff: | |
lea ecx, [t + esi] ; get t[esi] | |
mov eax, 4 ; sys_call write | |
mov ebx, 1 ; sys_call file stdout | |
mov ecx, ecx ; get char at esi index | |
mov edx, 0x1 ; set length | |
int 0x80 ; call kernel | |
jmp _exit | |
_exit: | |
mov eax, 1 ; sys_call exit | |
int 0x80 ; call kernel | |
section .data | |
s: db "abcde", 0 | |
s_len equ $-s | |
t: db "abcdef", 0 | |
t_len equ $-t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment