【发布时间】:2015-10-04 21:59:14
【问题描述】:
我正在努力创建函数并在程序集中调用它们。
函数gfx_draw_h(color, x_1, y_1, x_2) 应该是从(x_1, y_1) 到(x_2, y_1) 画一条线,但我无法将x_2 的值与gfx_draw_h.repeat 中的当前位置进行比较。
另外,另一段代码是否正确(没有堆栈损坏)?
这是我的代码:
BITS 16
; ----------------------------------------------------------------------
_start:
mov ax, 07C0h
add ax, 288
mov ss, ax ; SS = stack space
mov sp, 4096 ; SP = stack pointer
mov ax, 07C0h
mov ds, ax ; DS = data segment
call gfx_init
push 50 ; x_2
push 30 ; y_1
push 30 ; x_1
push 1000b ; color
call gfx_draw_h
add esp, 16
jmp $ ; infinite loop
; ----------------------------------------------------------------------
; Initializes graphics.
;
; Sets the video mode.
;
; INPUT:
; none
;
; OUTPUT:
; none
;
gfx_init:
mov ah, 00h ; set video mode
mov al, 12h ; AL = graphical mode
int 10h ; INT 10h / AH = 00h
ret
; ----------------------------------------------------------------------
; Draws a horizontal line.
;
; INPUT:
; color
; x_1
; y_1
; x_2
;
; OUTPUT:
; none
;
gfx_draw_h:
pop ax ; color
pop cx ; x
pop dx ; y
mov ah, 0Ch ; change color for a single pixel
.repeat:
cmp cx, [ebp + 20] ; !!! THIS IS THE ISSUE !!!
je .done
inc cx
int 10h
jmp .repeat
.done:
ret
; ----------------------------------------------------------------------
times 510 - ($ - $$) db 0 ; padding with 0 at the end
dw 0xAA55 ; PC boot signature
【问题讨论】: