中断 10h 不起作用 [英] Interrupt 10h not working

查看:26
本文介绍了中断 10h 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的程序中遇到分段错误.
这是用于设置屏幕左上角的光标.但是为什么我在这个程序上遇到分段错误?感谢您的回复.

I am getting segmentation fault in the program below.
This is for set the cursor on the top-left of the screen. But why i am getting segmentation fault on this program? Thanks for the replies.

section .text
global main
main:
    mov ah, 2
    mov bh, 1
    mov dh, 0
    mov dl, 0
    int 10h

我认为问题在于我正在使用的保护模式.这是一条 16 位指令,我正在 32 位机器上尝试!我说得对吗?

I think that the problem is the protected mode that i am working. This is an 16-bit instruction and i am trying this in a 32-bit machine! Am i correct?

我在 32 位 Linux Ubuntu 发行版中运行此程序.处理器为AMD C-60.

I am running this program in a Linux Ubuntu distribution 32-bits. THe processor is AMD C-60.

推荐答案

BIOS 中断是 16 位代码.您的操作系统已将 CPU 置于 32 位保护模式.硬件将允许切换回 16 位实模式(需要跳过一些障碍),但操作系统不允许.如果确实如此,就不会受到很大的保护".它受到美国的保护",我的朋友!

BIOS interrupts are 16-bit code. Your OS has put the CPU in 32-bit protected mode. The hardware will allow a switch back to 16-bit real mode (there are hoops to jump through) but the OS won't allow it. Wouldn't be very "protected" if it did. It is "protected" from US, my friend!

我认为您可能想要研究的是vt100"终端仿真.按理说,一个健壮"的程序会在尝试使用之前查阅termcaps"文件以确保 vt100 仿真可用.我的经验是它通常"在桌面 Linux"机器上可用,所以我只是假设它在那里.如果我们假设错误,可能发生的最糟糕的事情(我认为)就是屏幕上的垃圾.

I think what you probably want to look into is "vt100" terminal emulation. By rights, a "robust" program would consult the "termcaps" file to make sure vt100 emulation is available before attempting to use it. My experience is that it's "usually" available on a "desktop Linux" box, so I just ASSume it's there. Worst that can happen (I think) is garbage on the screen if we ASSume wrong.

这个例子并不完全符合你的要求.它保存当前光标位置(天知道在哪里),将光标移动到一个新位置,打印一条消息,然后回到原来的光标位置.您需要查找home cursor"命令(ESC [h"?lookitup).只需将其写入标准输出,与hello world"相同.你也可以获得颜色和东西.

This example doesn't do exactly what you want. It saves the current cursor position (lord knows where), moves the cursor to a new position, prints a message, and goes back to the original cursor position. You'll need to look up the "home cursor" command ("ESC [h"? lookitup). Just write it to stdout, same as "hello world". You can get colors and stuff, too.

; nasm -f elf32 mygem.asm
; ld -o mygem mygem.o -melf_i386

global _start

section .data
savecursor db 1Bh, '[s'
.len equ $ - savecursor

unsavecursor db 1Bh, '[u'
.len equ $ - unsavecursor

getcursor db 1Bh, '[6n'
.len equ $ - getcursor

setcursor db 1Bh, '[10;20H'
.len equ $ - setcursor

msg db "Hello, new cursor position!"
.len equ $ - msg

section .text
_start:

mov ecx, savecursor
mov edx, savecursor.len
call write_stdout


mov ecx, setcursor
mov edx, setcursor.len
call write_stdout

mov ecx, msg
mov edx, msg.len
call write_stdout

mov ecx, unsavecursor
mov edx, unsavecursor.len
call write_stdout

exit:
mov eax, 1
xor ebx, ebx
int 80h

;------------------------
write_stdout:    
push eax
push ebx
mov eax, 4
mov ebx, 1
int 80h
pop ebx
pop eax
ret
;---------------------

这篇关于中断 10h 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆