; Basic Assembly
; ==============
; 
; Memory ideas
; ------------
;
; Snake
; @@@@@
;
; 0.    Assemble and run this program.
;
; 1.    How many inputs does this program require? 
;       Try to give the program some inputs, and check out the results. 
;
;       How does the output look like? What does it mean?
;
; 2.    Read the program's code below, and try to understand what does it do. 
;       Try to describe it as simply as you can. Add comments if needed.
;
; 3.    What is special about the data array world? Could you create a data
;       array with the same special property yourself?
;
; 4*.   Bonus: How many data arrays like world of a fixed length n exist?
;

BITS 32
global main
extern exit

%include "training.s"

; ===============================================
section .data
    world   db      0x2e,0x99,0xba,0x21,0x4b,0x7d,0xf4,0x54,0xa1,0xb8,0x41
            db      0x12,0xf3,0x64,0xc7,0x4a,0x1b,0x9f,0x40,0x79,0xf5,0xa5
            db      0x58,0xa0,0xda,0x34,0xbe,0xdc,0xde,0x6e,0x70,0xec,0x24
            db      0xce,0x5d,0x3e,0x37,0x3a,0xd5,0xc9,0xa2,0xb7,0x14,0x78
            db      0xfe,0x91,0x38,0x51,0x44,0x30,0xed,0xcd,0xa4,0xa8,0x82
            db      0x8b,0x73,0x9b,0xc2,0x3f,0x23,0x72,0xf1,0x59,0x6a,0x29
            db      0x68,0x5c,0xe1,0xe7,0x1f,0x43,0xe6,0xbc,0x94,0xe9,0x10
            db      0x0c,0x80,0x2b,0xeb,0xe3,0xee,0x0e,0x53,0xbb,0xc0,0x7b
            db      0x9e,0xae,0xca,0x07,0xac,0x17,0xcc,0x55,0x33,0xa7,0x8c
            db      0x46,0xf2,0x9a,0xea,0x35,0x8f,0x50,0x69,0xc3,0x45,0xb1
            db      0x6f,0xb3,0x4c,0x36,0x7f,0xcb,0x31,0x63,0x75,0x11,0x71
            db      0xb4,0x7c,0x8e,0xdb,0x98,0xbd,0x84,0xf0,0xd0,0xcf,0xb6
            db      0xa9,0xaa,0x0a,0x9c,0x92,0x6c,0x48,0xe8,0x61,0xb0,0xc6
            db      0x4e,0x16,0x95,0x3d,0x0f,0x5a,0x52,0x88,0x86,0x97,0x66
            db      0x25,0xb2,0x90,0xd2,0xfd,0x57,0xb9,0xab,0x9d,0x00,0x4f
            db      0x5e,0x18,0x02,0x76,0x3c,0x1d,0x74,0xf6,0x2f,0x39,0xf7
            db      0xaf,0x2a,0x13,0x6b,0xf9,0xd6,0x93,0xc8,0x6d,0x8a,0xe2
            db      0x22,0x8d,0x15,0xc4,0xd3,0x67,0x08,0xc1,0xdf,0x96,0x42
            db      0x60,0xfc,0x04,0x05,0xe4,0xe5,0x0b,0xff,0x2c,0xd8,0xfa
            db      0x77,0x0d,0x27,0xe0,0x01,0xd1,0x1c,0x5b,0xd4,0x1a,0x06
            db      0x3b,0x87,0x20,0xf8,0x62,0x28,0xbf,0xa6,0xad,0xef,0x47
            db      0xc5,0xa3,0x32,0x09,0x1e,0xd9,0x89,0x56,0x26,0x65,0xdd
            db      0x83,0x7e,0x5f,0x81,0x85,0x4d,0x03,0x19,0xb5,0x7a,0x2d
            db      0xfb,0xd7,0x49

; ===============================================
section .text

main:
    call    read_hex
    and     eax,000000ffh   ; Discard the higher bytes of the input.
    mov     edx,eax         ; Save first location in edx.
    xor     ecx,ecx         ; Hop count.

    mov     esi,world

next_location:
    call    print_eax
    movzx   eax,byte [esi + eax]
    inc     ecx
    cmp     eax,edx
    jnz     next_location

    call    print_delimiter
    ; print hop count:
    mov     eax,ecx
    call    print_eax

    ; Exit the process:
    push    0
    call    exit

