TASM 주소 지정

Sep 12 2020

저는 현재 대학을 위해 Snake를 구현하고 있으며이를 위해 TASM을 사용해야합니다.

내 주요 게임 데이터는 다음과 같이 배치됩니다 (C 구문 사용).

struct GameLine {
    uint8_t direction_bits[10];  // 2 bits per entry, the first entry is invalid since valid x positions start at one
    uint8_t collision_bits[5];  // 1 bit per entry, the first entry is again invalid but has to stay zero
    uint8_t aux;  // padding such that GameLine is 16 bytes big, also used to store other information at times.
};

struct GameData {
    struct GameLine lines[23];
} PHYSICAL_GAME_DATA;

문제는 각 프레임의 방향 비트를 쓰면 큰 x 위치에 대한 읽기 충돌 비트를 덮어 쓰는 것입니다 (38이 최대 위치이지만 더 일찍 발생 함). physical_game_data어셈블러 ( tasm) 및 / 또는 링커 ( tlink) 및 / 또는 디버거 ( td) 에이 를 표시 하는 방법을 모르기 때문에 실제 위치를 확인할 수 없었기 때문에 "충돌 비트 읽기" 라고 말합니다.

내 코드의 선언은 다음과 같습니다.

physical_game_data   DB 368 DUP (0)
; ..., Some `EQU`s for `aux` data I'm using to store other information
game_data EQU (offset physical_game_data) - 16  ; Since 1 <= y <= 23, this allows addressing a line via `game_data + (y << 4)`

mov내가 가장 여기에 대해 걱정 것을들 (몇 가지 더있다, 그러나 이러한 버그 볼을 두를 수 있습니다 것은)이 두 가지 있습니다 :

; This one is for writing a new direction
mov     BYTE [ds:game_data + bx],   dh
; ...
; This one is for reading a collision bit to check if the player lost
mov     dl,     [ds:game_data + 10 + si]

td그러나 그것들을 보면 다음과 같은 결과가 나옵니다.

mov [bx+05AF],dh
; ...
mov dl,[si+05B8]

그러나 0x05AF와 0x05B8의 차이는 10이 아니라 9입니다. 현재 소스 코드에 11을 추가하여 문제를 "수정"했습니다. 이는 버그가 발생하지 않는다는 것을 의미하지만이 문제를 제대로 해결하고 싶습니다.

나는 이것이 내가 TASM 또는 x86 / x86-16 어셈블리에 대해 오해하고 있다고 가정하고 있지만 그 오해가 정확히 무엇인지 모르겠습니다.

다음은이 문제를 보여주는 전체 파일입니다.


    .model  tiny
    .286

.data
datastart:
physical_game_data  DB 368 DUP (0)
; ..., Some `EQU`s for `aux` data I'm using to store other information
game_data           EQU (offset physical_game_data) - 16  ; Since 1 <= y <= 23, this allows addressing a line via `game_data + (y << 4)`

.code

        ORG 100h
start:
        mov         ax,                         seg datastart
        mov         ds,                         ax

        ; This one is for writing a new direction
        mov         BYTE [ds:game_data + bx],   dh
        ; ...
        ; This one is for reading a collision bit to check if the player lost
        mov         dl,                         [ds:game_data + 10 + si]

        ; Exit
        mov         ax,                         4C00h
        int         21h
end start

사용하여 컴파일 된 tasm MRE.ASM, tlink MRE.OBJ및 연 td사용 td MRE.EXE의 디 컴파일 코드 읽기 :

mov ax,48AF
mov ds,ax
mov [bx+0103],dh
mov dl,[si+010C]
mov ax,4C00
int 21

여기서 다시 0x10C-0x103은 9입니다.

관심이 있다면 Dosbox에서이 코드를 실행하고 있습니다.

감사!

답변

5 RossRidge Sep 11 2020 at 23:34

문제는 BYTE 키워드입니다. MASM 모드에서 BYTE 키워드는 다음과 같이 BYTE의 크기로 평가됩니다. 1. []대괄호가 주로 MASM 모드에서 더하기 연산자 역할을하므로 대괄호의 표현식에 추가됩니다. BYTE PTR [ds:game_data + bx]대신 작성해야 하지만, 다음 지침에서 생략 할 수도 있음을 보여줍니다.