[os] 打印字符串

来源:互联网 发布:最新的mac版本是多少 编辑:程序博客网 时间:2024/04/29 23:07

 

第一个例子原理很简单,但若没有一定的汇编实践经验,还是很容易在各种各样的细节上栽跟头的。

下面是我完成任务后的一些总结:

 

1. 我学习汇编的教材是基于dos的, 里面既介绍了bios中断,又介绍了dos中断,我没有注意两者的区别,直接调用了一个dos中断,结果搞了半天愣是没有结果。

所以使用中断时要注意区分两者, linux下不支持dos。

 

2. 写显存和调用int 10h(bios中断) 可以达到一样的效果。

 

3. 如果有一个字符串需要打印, 例如: PrintMsg: db "hello world";

此时若用ds:si 指向该字符串首地址,ds=PrintMsg, di=0 无法正确读取字符串。

可以让ds=cs, si=PrintMsg。 具体原因我现在也说不太清楚。

 

具体代码如下: 

hello.asm(需要了解一下bios 10h中断): 

----------------------------------------------------

org 07c00h

mov ax, cs

mov es, ax

 

mov bx, 000ch     ; char attribute

mov cx, 13        ; the string length

mov dh, 1         

mov dl, 1         ; row and column

 

mov bp, ScreenMsg ; the adress of string

 

mov ax, 1301h     ; show the string

int 10h

 

jmp $

ScreenMsg: db  "hello wupeng!"

times 510-($-$$) db 0

dw 0xaa55

-----------------------------------------------------

 

 

boot.sh:

-----------------------------------------------------

#!/bin/bash

nasm hello.asm -o hello.bin

dd if=hello.bin of=a.img bs=512 count=1 conv=notrunc

-----------------------------------------------------