汇编代码在虚拟机上输出大量的'U'

时间:2014-09-23 13:13:23

标签: assembly virtualbox bootloader

我是一个装配新手,所以这可能是我的错误,但据我研究过,这个程序:

[BITS 16]    
[ORG 0x7C00]     
;============> START <=============================
Key:
mov ah,1
int 16h
mov ah,0Ah
int 10h
call Key
;============> END <===============================
times 510-($-$$) db 0
dw 0xAA55

应等待键盘输入,然后写入键入的ASCII字符。当我运行它(在用NASM构建它之后)它只输出大量的“U&#39;字符,直到它在3-4秒后离开视频内存(我认为)。

如果重要的话我使用ubuntu 14.04,编辑和ac程序的崇高文本首先将代码编译为.bin,然后将.bin转换为我在virtualbox中使用的.img。

1 个答案:

答案 0 :(得分:2)

您使用Int 16h,AH = 01h的中断立即返回,如果有击键可以清除Z标志,否则设置,所以您的程序不会等待击键。

您可以通过使用Int 16h,AH = 00h实际等待击键来等待击键,或修改您的代码以跳转直到有击键,如下所示:

Key:
  mov ah,1       ;
  int 16h        ; check for keystroke - clear Z flag if keystroke, AL = char
  jz Key         ; keep looping until there is a key pressed
  xor bx,bx      ; clear BX (page = 0)
  mov cx,1       ; and rep count (1)
  mov ah,0Ah     ; write char at cursor position
  int 10h        ;
  jmp Key        ; this should be a jmp rather than a call