assembly - 有关 VGA 和 putpixel intel x86 asm AT&T 语法的帮助

标签 assembly x86 vga att

我想在asm中画一条彩色线。我必须在 x86 intel linux 单元上使用 AT&T 语法。 我已经了解了很多,但我想知道如何进入 VGA 模式或 X 模式,以及如何在屏幕上放置像素。标准 C 库中是否有相应的函数(如 printf)?

非常感谢您的帮助。 :)

<p>.bss # Declaring uninitialized variables</p> <p>.data # Declaring initialized variables</p> <p>.text # Actual assembly code and constants</p> <pre><code>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) </code></pre> <p>main: pushl %ebp # Push base pointer movl %esp, %ebp # Initialize base pointer pushl $intro # Push the string address call printf # Call the printf routine from C library addl $8, %esp</p> <pre><code>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 </code></pre> <p>red: #... still working on this</p> <pre><code> 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 </code></pre> <p>draw:<br/> call putpixel # pushl %ebp # Push the base pointer # movl %esp, %ebp # Initialize base pointer inc %ebx # increment X inc %ecx # increment Y cmpl $200, %ecx # check if Y => 200 jge end # if Y=> 200, jump to end jmp draw # loop </p> <p>putpxl: #has to put a pixel at (%ebx, %ecx) and return to draw # should use the color from the main routine</p> <p>end: movl %ebp, %esp # Remove local variables popl %ebp # Remove base pointer ret # return to main routine </p>

最佳答案

您能做的最好的事情就是使用更高级别的库,例如 SDL 或 Allegro。这样,您的程序将在 X11 和非 VGA 帧缓冲区上运行(例如:基于 ARM 的嵌入式设备上的显示)。

Svgalib 允许对 VGA 和所谓的 SVGA 显卡进行编程。它的开发几年前就停止了。

访问 VGA 硬件有两种方法:

  • 使用寄存器
  • 使用 VGA BIOS:这是您尝试过的。 VGA BIOS 被编写为在实模式下运行。要从保护模式调用它们,您需要切换到 vm86 模式。这就是 LRMI(Linux 实模式接口(interface),与 DPMI 相反)所做的。

关于assembly - 有关 VGA 和 putpixel intel x86 asm AT&T 语法的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6874846/

相关文章:

iphone - 处理 iPad 上的外部屏幕

C++ - 常量和优化

assembly - x86组装极限新手查询: "invalid instruction operands"?

c - 如何使用 Assembly 加载 C 应用程序?

c - 我如何让 GCC 在 ah/bh/ch/dh 中放置一个字符?

assembly - 无法理解调用者不需要清理堆栈的 cdecl 调用约定示例

assembly - 如何更改字符串的前景色(32 位汇编内核)?

c - 错误代码如何返回给用户程序?

c++ - 在 x86(32 位)程序集中实例化一个 c++ 类(通过复制将 c++ 类传递给程序集中的方法)

linux - svgalib : cant see anything