X86 - What size variable to use (db, dw, dd)

I am starting to build and I do not know what all things db, dw, dd mean. I tried to write this little script that does 1 + 1, save it in a variable, and then display the result. Here is my code:

.386 .model flat, stdcall option casemap :none include \masm32\include\windows.inc include \masm32\include\kernel32.inc include \masm32\include\masm32.inc includelib \masm32\lib\kernel32.lib includelib \masm32\lib\masm32.lib .data num db ? ; set variable . Here is where I don't know what data type to use. .code start: mov eax, 1 ; add 1 to eax register mov ebx, 1 ; add 1 to ebx register add eax, ebx ; add registers eax and ebx push eax ; push eax into the stack pop num ; pop eax into the variable num (when I tried it, it gave me an error, i think thats because of the data type) invoke StdOut, addr num ; display num on the console. invoke ExitProcess ; exit end start 

I need to understand what db, dw, dd things mean and how they affect setting and combining variables and such things.

Thanks in advance, Progrmr

+44
variables assembly x86
Apr 16 2018-12-12T00:
source share
2 answers

DB - byte definition. 8 bit

DW - definition of a word. Usually 2 bytes on a standard x86 32-bit system

DD . Define a double word. Usually 4 bytes on a standard x86 32-bit system

From x86 assembly tutorial ,

The pop command removes a 4-byte data element from the top of the stack associated with the equipment into the specified operand (i.e. register or memory). First, it moves 4 bytes located in the memory location [SP] to the specified register or memory location, and then increases the SP by 4.

Your number is 1 byte. Try declaring it with DD so that it becomes 4 bytes and matches the semantics of pop .

+55
Apr 16 2018-12-12T00:
source share

Full list:

DB, DW, DD, DQ, DT, DDQ, and DO (used to declare initialized data in the output file.)

See: http://www.tortall.net/projects/yasm/manual/html/nasm-pseudop.html

They can be called in various ways: (Note: for Visual-Studio use "h" instead of the "0x" syntax - for example: not 0x55, but instead of 55h):

  db 0x55 ; just the byte 0x55 db 0x55,0x56,0x57 ; three bytes in succession db 'a',0x55 ; character constants are OK db 'hello',13,10,'$' ; so are string constants dw 0x1234 ; 0x34 0x12 dw 'A' ; 0x41 0x00 (it just a number) dw 'AB' ; 0x41 0x42 (character constant) dw 'ABC' ; 0x41 0x42 0x43 0x00 (string) dd 0x12345678 ; 0x78 0x56 0x34 0x12 dq 0x1122334455667788 ; 0x88 0x77 0x66 0x55 0x44 0x33 0x22 0x11 ddq 0x112233445566778899aabbccddeeff00 ; 0x00 0xff 0xee 0xdd 0xcc 0xbb 0xaa 0x99 ; 0x88 0x77 0x66 0x55 0x44 0x33 0x22 0x11 do 0x112233445566778899aabbccddeeff00 ; same as previous dd 1.234567e20 ; floating-point constant dq 1.234567e20 ; double-precision float dt 1.234567e20 ; extended-precision float 

DT does not accept numeric constants as operands, and DDQ does not accept floating point constants as operands. Any size other than DD does not accept strings as operands.

+18
Mar 21 '14 at 9:27
source share



All Articles