1 ; testdata.asm a program to demonstrate data types and values 2 ; 3 ; assemble: nasm -f elf -l testdata.lst testdata.asm 4 ; link: gcc -o testdata testdata.o 5 ; run: testdata 6 ; Look at the list file, testdata.lst 7 8 ; Note! nasm ignores the type of data and type of reserved 9 ; space when used as memory addresses. 10 ; You may have to use qualifiers BYTE, WORD or DWORD [dd01] 11 12 13 section .data ; data section 14 ; initialized, writeable 15 16 ; db for data byte, 8-bit 17 00000000 FF0111 db01: db 255,1,17 ; decimal values for bytes 18 00000003 FFAB db02: db 0xff,0ABh ; hexadecimal values for bytes 19 00000005 616263 db03: db 'a','b','c' ; character values for bytes 20 00000008 616263 db04: db "abc" ; string value as bytes 'a','b','c' 21 0000000B 616263 db05: db 'abc' ; same as "abc" three bytes 22 0000000E 68656C6C6F0D0A00 db06: db "hello",13,10,0 ; "C" string including cr and lf 23 24 ; dw for data word, 16-bit 25 00000016 3930EFFF2000 dw01: dw 12345,-17,32 ; decimal values for words 26 0000001C FFFFCDAB dw02: dw 0xFFFF,0abcdH ; hexadecimal values for words 27 00000020 6100616261626300 dw03: dw 'a','ab','abc' ; character values for words 28 00000028 68656C6C6F00 dw04: dw "hello" ; three words, 6-bytes allocated 29 30 ; dd for data double word, 32-bit 31 0000002E 15CD5B07F9FFFFFF dd01: dd 123456789,-7 ; decimal values for double words 32 00000036 FFFFFFFF dd02: dd 0xFFFFFFFF ; hexadecimal value for double words 33 0000003A 61000000 dd03: dd 'a' ; character value in double word 34 0000003E 68656C6C6F000000 dd04: dd "hello" ; string in two double words 35 00000046 AF7D2773 dd05: dd 13.27E30 ; floating point value 32-bit IEEE 36 37 ; dq for data quad word, 64-bit 38 0000004A C86BB752A7D0737E dq01: dq 13.27E300 ; floating point value 64-bit IEEE 39 40 ; dt for data ten of 80-bit floating point 41 00000052 4011E5A59932D5B6F0- dt01: dt 13.270E3000 ; floating point value 80-bit in register 42 0000005B 66 43 44 45 46 section .bss ; reserve storage space 47 ; uninitialized, writeable 48 49 00000000 s01: resb 10 ; 10 8-bit bytes reserved 50 0000000A s02: resw 20 ; 20 16-bit words reserved 51 00000032 s03: resd 30 ; 30 32-bit double words reserved 52 000000AA s04: resq 40 ; 40 64-bit quad words reserved 53 000001EA s05: resb 1 ; one more byte 54 55 SECTION .text ; code section 56 global main ; make label available to linker 57 main: ; standard gcc entry point 58 59 60 00000000 A0[00000000] mov al,[db01] ; correct to load a byte 61 00000005 8A25[00000000] mov ah,[db01] ; correct to load a byte 62 0000000B 66A1[16000000] mov ax,[dw01] ; correct to load a word 63 00000011 A1[2E000000] mov eax,[dd01] ; correct to load a double word 64 65 00000016 A0[00000000] mov al,BYTE [db01] ; redundant, yet allowed 66 67 0000001B 66A1[00000000] mov ax,[db01] ; no warning, loads two bytes 68 00000021 A1[16000000] mov eax,[dw01] ; no warning, loads two words 69 70 ; mov ax,BYTE [db01] ; error, size miss match 71 ; mov eax,WORD [dw01] ; error, size miss match 72 73 ; push BYTE [db01] ; error, can not push a byte 74 00000026 66FF35[16000000] push WORD [dw01] ; "push" needs to know size 2-byte 75 0000002D FF35[2E000000] push DWORD [dd01] ; "push" needs to know size 4-byte 76 ; push QWORD [dq01] ; error, can not push a quad word 77 00000033 FF35[4E000000] push DWORD [dq01+4] ; push a floating point, half of it 78 00000039 FF35[4A000000] push DWORD [dq01] ; push other half of floating point 79 0000003F D905[46000000] fld DWORD [dd05] ; floating load 32-bit 80 00000045 DD05[4A000000] fld QWORD [dq01] ; floating load 64-bit 81 82 0000004B BB00000000 mov ebx,0 ; exit code, 0=normal 83 00000050 B801000000 mov eax,1 ; exit command to kernel 84 00000055 CD80 int 0x80 ; interrupt 80 hex, call kernel 85 86 ; end testdata.asm