我是NASM的新手(以及一般的汇编程序),我正在寻找在NASM中获得控制台大小(控制台数量和行数)的方法。像AH=0Fh和Int10h:http://en.wikipedia.org/wiki/INT_10H
现在,我明白了,在NASM (和一般的linux )中,我不能中断BIOS,所以必须有其他方法。
其想法是打印一些输出以填满屏幕,然后等待用户按ENTER键,直到打印更多输出。
发布于 2015-05-03 05:05:29
如果您在Linux中编程,那么您必须使用可用的系统调用来实现您的目标。这并不是说没有中断。系统调用本身通过中断调用来执行。但是,在内核之外,您将无法访问它们,而且,由于内核在保护模式下运行,即使您可以访问它们,它们也可能不会执行您所期望的操作。
然而,对于你的问题。要获得控制台大小,您需要使用ioctl系统调用。这是通过EAX中的值0x36访问的。我建议您通读一下the manual page for ioctl,您可能还会发现this system call table非常有用!
发布于 2015-05-21 16:32:42
这是一个我很久以前就必须处理的问题。unistd.inc和termio.inc的代码可以在includes文件夹中找到here。可以在de tree programs/basics/terminal-winsize中找到该程序和makefile。
可以在任何终端(控制台)上获取的行和列的值。只有在某些终端上才能获得x像素和ypixels。(xterm是的,gnome终端取决于)。因此,如果你不能从一些终端获得x和y像素(屏幕大小),我猜终端是基于文本的。如果它有其他原因导致这种行为,请纠正我。
您可以很容易地将此程序转换为32位,因为它使用nasmx宏的syscall,。唯一需要做的就是替换32位寄存器中的64位寄存器,并将一些参数放入正确的寄存器中。在github上查找agguro以查看所有包含文件。
我希望这对你有帮助
; Name: winsize
; Build: see makefile
; Run: ./winsize
; Description: Show the screen dimension of a terminal in rows/columns.
BITS 64
[list -]
%include "unistd.inc"
%include "termio.inc"
[list +]
section .bss
buffer: resb 5
.end:
.length: equ $-buffer
lf: resb 1
section .data
WINSIZE winsize
; keep the lengths the same or the 'array' construction will fail!
array: db "rows : "
db "columns : "
db "xpixels : "
db "ypixels : "
.length: equ $-array
.items: equ 4
.itemsize: equ array.length / array.items
section .text
global _start
_start:
mov BYTE[lf], 10 ; end of line in byte after
buffer
; fetch the winsize structure data
syscall ioctl, STDOUT, TIOCGWINSZ, winsize
; initialize pointers and used variables
mov rsi, array ; pointer to array of strings
mov rcx, array.items ; items in array
.nextVariable:
; print the text associated with the winsize variable
push rcx ; save remaining strings to process
push rdx ; save winsize pointer
syscall write, STDOUT, rsi, array.itemsize
pop rax ; restore winsize pointer
push rax ; save winsize pointer
; convert variable to decimal
mov ax, WORD[rax] ; get value form winsize structure
mov rdi, buffer.end-1
.repeat:
xor rbx, rbx ; convert value in decimal
mov bx, 10
xor rdx, rdx
div bx
xchg rax, rdx
or al, "0"
std
stosb
xchg rax, rdx
cmp al, 0
jnz .repeat
push rsi ; save pointer to text
; print the variable value
mov rsi, rdi
mov rdx, buffer.end ; length of variable
sub rdx, rsi
inc rsi
syscall write, STDOUT, rsi, rdx
pop rsi
pop rdx
; calculate pointer to next variable value in winsize
add rdx, 2
; calculate pointer to next string in strings
add rsi, array.itemsize
; if all strings processed
pop rcx ; remaining arrayitems
loop .nextVariable
; exit the program
syscall exit, 0https://stackoverflow.com/questions/29340736
复制相似问题