Skip to main content

Posts

Showing posts from August 11, 2019

receives 5 numbers, and prints them back in reverse order assembly yasm/nasm/fasm

This program receives 5 numbers, and prints them back in reverse order. yasm - BITS 32 global main extern exit section .data     ; 5 dwords:     keep_nums  times 5  dd (12345678h)     section .text main:     mov ecx, 5   read_one_number:     dec     ecx     call    read_hex     mov     esi,ecx     ; Calculate the address of dword number ecx:     shl     esi,2 ; multiply by 4. Every dword is 4 bytes!     add     esi,keep_nums     ; Store the number inside dword number ecx:     mov     dword [esi],eax     test    ecx,ecx     jnz     read_one_number     mov     edi,5     mov     ecx,0 ; Now we print all the numbers, in reverse order: print_one_number:     mov     esi,ecx     ; Calculate the address of dword number ecx:     shl     esi,2     add     esi,keep_nums     ; Read from dword number ecx:     mov     eax,dword [esi]     call    print_eax     inc     ecx     cmp     ecx,edi     jnz     print_one_number            push    0     ca

dup (nasm) alternative times for yasm

 yasm ------- BITS 32 global main extern exit %include    'training.s'   ;=========================================== section .data     ; 5 dwords:      keep_nums  times 5  dd (12345678h)     section .text main:     mov ecx, 5   read_one_number:     dec     ecx     call    read_hex     mov     esi,ecx     ; Calculate the address of dword number ecx:     shl     esi,2 ; multiply by 4. Every dword is 4 bytes!     add     esi,keep_nums     ; Store the number inside dword number ecx:     mov     dword [esi],eax     test    ecx,ecx     jnz     read_one_number     mov     edi,5     mov     ecx,0 ; Now we print all the numbers, in reverse order: print_one_number:     mov     esi,ecx     ; Calculate the address of dword number ecx:     shl     esi,2     add     esi,keep_nums     ; Read from dword number ecx:     mov     eax,dword [esi]     call    print_eax     inc     ecx     cmp     ecx,edi     jnz     print_one_number