【发布时间】:2011-10-16 00:48:42
【问题描述】:
我想在 asm 中画一条彩色线。我必须在 x86 intel linux 单元上使用 AT&T 语法。 我已经走得很远了,但我想知道如何进入 VGA 模式或 Mode-X,以及如何在屏幕上放置一个像素。标准 C 库(如 printf)中是否有此功能?
非常感谢您的帮助。 :)
<pre></pre>
.bss # 声明未初始化的变量
.data # 声明初始化变量
.text # 实际汇编代码和常量
intro: .asciz "Draw a line in VGA\n\n"
clr: .asciz "Give a color \n"
optns: .asciz "red (1), blue (2), white (3)\n"
res .asciz "%d"
ent: .asciz "\n"
.global main # Tell kernel where to start (visible from outside)
main: pushl %ebp # 压入基指针 movl %esp, %ebp # 初始化基指针 pushl $intro # 推送字符串地址 call printf # 从 C 库中调用 printf 例程 添加 $8, %esp
pushl $clr # push color question on the stack
call printf # Print it
subl $4, %esp # Reserve stack space for variable
leal -4(%ebp), %eax # Load address of stack var in eax
pushl %eax # Push second argument of scanf
pushl $rets # Push first argument of scanf
call scanf # Call scanf
movl 4(%ebp), %ecx # mov the result in ecx
cmpl $1, %ecx
je red
cmpl $2, %ecx
je blue
jne white
red: #... 仍在努力
movl 0013h, %eax # enter 320x200x256 mode
int 10h # IS THIS CORRECT?
movl $0, %ebx # set X to 0
movl $0, %ecx # set Y to 0
call draw # Call line routine
movl 0003h, %eax # IS THIS CORRECT?
int 10h # return to text mode
movl $0, (%esp) # Make esp 0, indicating succesful termination
call exit # Exit the program
画:
调用 putpixel
# pushl %ebp # 压入基指针
# movl %esp, %ebp # 初始化基指针
inc %ebx # 增量 X
inc %ecx # 增量 Y
cmpl $200, %ecx # 检查 Y => 200
jge end # 如果 Y=> 200,跳转到结束
jmp draw # 循环
putpxl: #必须在 (%ebx, %ecx) 放置一个像素并返回绘图 # 应该使用主程序中的颜色
end: movl %ebp, %esp # 移除局部变量 popl %ebp # 删除基指针 ret # 返回主程序
【问题讨论】: