Programing

x86 어셈블리에서 사용할 변수 크기 (db, dw, dd)는 무엇입니까?

lottogame 2020. 12. 12. 09:55
반응형

x86 어셈블리에서 사용할 변수 크기 (db, dw, dd)는 무엇입니까?


나는 어셈블리 초보자이고 모든 db, dw, dd, 사물이 의미하는 바를 모릅니다. 1 + 1을 수행하는이 작은 스크립트를 작성하고 변수에 저장 한 다음 결과를 표시하려고했습니다. 지금까지 내 코드는 다음과 같습니다.

.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

나는 db, dw, dd가 무엇을 의미하는지, 변수 설정과 결합에 어떤 영향을 미치는지 이해해야합니다.

미리 감사드립니다, Progrmr


빠른 검토,

  • DB- 바이트 정의. 8 비트
  • DW- 단어 정의. 일반적인 x86 32 비트 시스템에서 일반적으로 2 바이트
  • DD- 더블 워드를 정의합니다. 일반적인 x86 32 비트 시스템에서 일반적으로 4 바이트

에서 튜토리얼 조립 86 ,

pop 명령어 는 하드웨어 지원 스택의 맨 위에서 지정된 피연산자 (예 : 레지스터 또는 메모리 위치)로 4 바이트 데이터 요소를 제거합니다 . 먼저 메모리 위치 [SP]에있는 4 바이트를 지정된 레지스터 또는 메모리 위치로 이동 한 다음 SP를 4 씩 증가시킵니다.

귀하의 번호는 1 바이트입니다. DD4 바이트가되고 pop의미 와 일치하도록 선언하십시오 .


전체 목록은 다음과 같습니다.

DB, DW, DD, DQ, DT, DDQ 및 DO (출력 파일에서 초기화 된 데이터를 선언하는 데 사용됨)

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

다음과 같은 다양한 방법으로 호출 할 수 있습니다. (참고 : Visual-Studio의 경우- "0x"구문 대신 "h"사용-예 : 0x55가 아니라 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's 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 float constants as operands. Any size larger than DD does not accept strings as operands.

참고URL : https://stackoverflow.com/questions/10168743/which-variable-size-to-use-db-dw-dd-with-x86-assembly

반응형