[英]Printing characters onto screen using Assembly
嗨,我在ubuntu 11.10中使用NASM並使用它編寫了一個程序,以下代碼將一次打印出一個字符。
[BITS 16] ;Tells the assembler that its a 16 bit code
[ORG 0x7C00] ;Origin, tell the assembler that where the code will
;segment .data
PROMPT1 db "HELLO WORLD",0x0
STAR db '*'
;segment .text
;global asm_main
;asm_main:
mov si, PROMPT1
mov al, [si]
;mov ecx, 11
loop_start:
call PRNTCHR
inc si
mov al, 0xA
call PRNTCHR
mov al, [si]
cmp al, 0
je $+4
loop loop_start
jmp $
PRNTCHR:
MOV AH, 0x0E ;Tell BIOS that we need to print one charater on screen.
MOV BH, 0x00 ;Page no.
MOV BL,0x0F ;Text attribute 0x07 is lightgrey font on black background
INT 0x10 ;Call video interrupt
RET ;Return to calling procedure
TIMES 510 - ($ - $$) db 0 ;Fill the rest of sector with 0
DW 0xAA55 ;Add boot signature at the end of bootloader
關於此代碼段,我確實有兩個問題。
你能幫我嗎?
即使在給定標識符的情況下,它也按原樣駐留在二進制文件中,在加載到源之后,處理器將繼續增加IP並運行代碼,當'*'存在時打印它的情況純屬巧合(當PROMPT1為轉換為說明!)。 有分段時不會發生這種情況,但是在此模式下,默認情況下不會啟用分段,將分段代碼移植到非分段代碼中時,您應該將非代碼數據內容放到要運行的代碼后面,這很簡單,感謝Alex(您想運行 )!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.