[英]Help on VGA and putpixel intel x86 asm AT&T syntax
I want to draw a colored line in asm. 我想在asm中绘制一条彩色线条。 I have to use AT&T syntax, on an x86 intel linux unit.
我必须在x86 intel linux上使用AT&T语法。 I got pretty far already, but I'd like to know how to enter VGA-mode, or Mode-X, and how to put a pixel on the screen.
我已经相当远了,但我想知道如何进入VGA模式,或模式X,以及如何在屏幕上放置像素。 Is there a function for that in a standard C library (like printf)?
在标准C库(如printf)中是否有这样的功能?
Thanks a lot for your help. 非常感谢你的帮助。 :)
:)
.bss # Declaring uninitialized variables
.data # Declaring initialized variables
.text # Actual assembly code and constants
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 # 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
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: #... still working on this
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
draw:
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
putpxl: #has to put a pixel at (%ebx, %ecx) and return to draw # should use the color from the main routine
end: movl %ebp, %esp # Remove local variables popl %ebp # Remove base pointer ret # return to main routine
You are not allowed to do direct video (graphic mode) output in linux (protected OS). 您不能在linux(受保护的操作系统)中执行直接视频(图形模式)输出。 it was possible only in a dos (real-mode OS).
它只能在dos(实模式操作系统)中使用。
You can use framebuffer device or SDL, or libX11. 您可以使用帧缓冲设备或SDL或libX11。 But there is no reason why to do work with high-level libraries from the asm.
但是没有理由与asm的高级库一起工作。
Int 10 is not allowed in linux directly (in user mode; the kernel must do low-level accesses). 直接在linux中不允许使用Int 10(在用户模式下;内核必须进行低级访问)。
eg this is 5 year old exact the same discussion http://www.gamedev.net/topic/368196-linux-assembler-int-10h/ 例如,这是5岁,完全相同的讨论http://www.gamedev.net/topic/368196-linux-assembler-int-10h/
Best thing you could do would be to use a higher-level library, like SDL or Allegro. 您可以做的最好的事情是使用更高级别的库,如SDL或Allegro。 This way, your program will work on top of X11 and on non-VGA framebuffers (eg: displays on embedded ARM-based devices).
这样,您的程序将在X11和非VGA帧缓冲区之上工作(例如:在基于ARM的嵌入式设备上显示)。
Svgalib allowed to program for VGA and so-called SVGA graphics cards. Svgalib允许为VGA和所谓的SVGA图形卡编程。 Its development stopped years ago.
它的发展在几年前停止了。
There are two ways to access VGA hardware: 有两种方法可以访问VGA硬件:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.