【发布时间】:2019-03-08 03:06:12
【问题描述】:
为了清楚起见,添加了实际代码,抱歉,我是来自我的开发 PC 的 AFK。在标有 XXXX 的行中,我有问题,如果我直接使用标签,我可以访问 wiseman 的值,但如果我尝试从堆栈中访问标签值,则不能。
stage2: ; stage 2 bootloader
push 50 ; y
push 50 ; x
push 06h ; first color, brown
push 0Ch ; second color, red
push wiseman ; sprite to draw
push 32 ; how many bytes the sprite has
call draw_sprite
cli
hlt
; 00 is always black and 11 is always white
draw_sprite:
push bp ; save old base pointer
mov bp, sp ; use the current stack pointer as new base pointer
pusha
mov cx, [bp + 12] ; x coordinate
mov dx, [bp + 14] ; y coordinate
; initializing to 0, saves one byte from using mov
xor si, si ; index of the bit we are checking (width)
xor di, di
.row: ; main loop, this will iterate over every bit of [rock], if it is a 1 the .one part will be executed, if it is a 0 the .zero part will
cmp si, 16 ; check if we have to move to the next byte/row
jne .same_row ; Byte checked
xor si, si ; this executes if we move to the next row
add di, 2 ; next row
cmp di, [bp + 4] ; if we have finished with the tile
je .done
inc dx
mov cx, [bp + 12] ; x coordinate
.same_row:
xor bh, bh ; store the color
mov ax, [wiseman + di] ;XXXXXXX works with wiseman + di but no with bp + 6 + di
bt ax, si ; first bit
jnc .next_bit
add bh, 1
.next_bit:
inc si
bt ax, si ; second bit
jnc .end_bit
add bh, 2
.end_bit:
cmp bh, 0 ; black
je .pass
cmp bh, 1 ; first_color
je .first_color
cmp bh, 2 ; second_color
je .second_color
cmp bh, 3 ; white
je .white
.first_color:
; draw
mov ah, 0Ch
xor bh, bh
mov al, [bp + 10]
int 10h
jmp .pass
.second_color:
; draw
mov ah, 0Ch
xor bh, bh
mov al, [bp + 8]
int 10h
jmp .pass
.white:
; draw
mov ah, 0Ch
xor bh, bh
mov al, 0Fh
int 10h
jmp .pass
.pass:
inc si
inc cx
jmp .row
.done:
popa
mov sp, bp
pop bp
ret 12
wiseman: dw 0x5400, 0x7700, 0x4500, 0x4500, 0x5E00, 0xFF80, 0x0FA0, 0xFBE8, 0xFAE9, 0xFAA9, 0xE8A9, 0xA8A8, 0xA8A8, 0xAA20, 0xAA00, 0x9680 ; 32 bytes
我想我有一个寻址问题,但我不完全明白为什么。
【问题讨论】:
-
您是否使用过调试器?你给
bp赋予了什么价值? -
好的,很抱歉我的问题一直是火车失事。我已经发布了实际代码。我是 AFK,虽然我很聪明,可以写一个简单的例子。
-
我也尝试过,但我认为我缺乏一些基本的了解。如果我将 mov ax, [wiseman + di] 更改为 mov ax, [bp + 6] 并添加 ax,di 仍然不起作用。
-
我只是在脑子里做这个,但是
push bp+call draw_sprite+push 32+push wiseman。 6? -
噢!
bp + 6是存储地址的位置。bp + 6 + 4不是存储地址的位置。想想:mov ax, [bp+6]mov ax, [ax+si]
标签: assembly x86 nasm bootloader