Skip to content

Instantly share code, notes, and snippets.

@lucasgolino
Created September 11, 2021 02:37
Show Gist options
  • Save lucasgolino/50b83fb2cf96293f936abb01e1deec09 to your computer and use it in GitHub Desktop.
Save lucasgolino/50b83fb2cf96293f936abb01e1deec09 to your computer and use it in GitHub Desktop.

Revisions

  1. lucasgolino created this gist Sep 11, 2021.
    46 changes: 46 additions & 0 deletions leetcode.asm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    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