下面的代码,可以在emu8086模拟器可以运行,请问怎么才能在masm32或者masmplus运行?

imur2008 2009-02-20 09:48:13
下面的代码,可以在emu8086模拟器可以运行,请问怎么才能在masm32或者masmplus运行?
name "hi-world"

; this example prints out "hello world!"
; by writing directly to video memory.
; in vga memory: first byte is ascii character, byte that follows is character attribute.
; if you change the second byte, you can change the color of
; the character even after it is printed.
; character attribute is 8 bit value,
; high 4 bits set background color and low 4 bits set foreground color.

; hex bin color
;
; 0 0000 black
; 1 0001 blue
; 2 0010 green
; 3 0011 cyan
; 4 0100 red
; 5 0101 magenta
; 6 0110 brown
; 7 0111 light gray
; 8 1000 dark gray
; 9 1001 light blue
; a 1010 light green
; b 1011 light cyan
; c 1100 light red
; d 1101 light magenta
; e 1110 yellow
; f 1111 white



org 100h

; set video mode
mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3)
int 10h ; do it!

; cancel blinking and enable all 16 colors:
mov ax, 1003h
mov bx, 0
int 10h


; set segment register:
mov ax, 0b800h
mov ds, ax

; print "hello world"
; first byte is ascii code, second byte is color code.

mov [02h], 'H'

mov [04h], 'e'

mov [06h], 'l'

mov [08h], 'l'

mov [0ah], 'o'

mov [0ch], ','

mov [0eh], 'W'

mov [10h], 'o'

mov [12h], 'r'

mov [14h], 'l'

mov [16h], 'd'

mov [18h], '!'




; color all characters:
mov cx, 12 ; number of characters.
mov di, 03h ; start from byte after 'h'

c: mov [di], 11101100b ; light red(1100) on yellow(1110)
add di, 2 ; skip over next ascii code in vga memory.
loop c

; wait for any key press:
mov ah, 0
int 16h

ret
...全文
493 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
imur2008 2009-02-22
  • 打赏
  • 举报
回复
知道了,原来是willflyz大侠将下面的参数才成加4了,怪不得呢。结贴致谢
mov BYTE PTR [SI+02h],'H'
mov BYTE PTR [SI+04h],'e'
mov BYTE PTR [SI+06h],'l'
mov BYTE PTR [SI+08h],'l'
mov BYTE PTR [SI+0ah],'o'
mov BYTE PTR [SI+0ch],','
mov BYTE PTR [SI+0eh],'W'
mov BYTE PTR [SI+10h],'o'
mov BYTE PTR [SI+12h],'r'
mov BYTE PTR [SI+14h],'l'
mov BYTE PTR [SI+16h],'d'
mov BYTE PTR [SI+18h],'!'
imur2008 2009-02-22
  • 打赏
  • 举报
回复
谢谢老大!!!
现在可以通过了
但是要是di+2,显示的时候是"hello,"这6个字是黄色的底,要是改为di+4,就全部是黄色的底,而emu8086那里是di+2就是全部的黄色的底

请问这个有什么不同?谢谢先

搞定加分
cnzdgs 2009-02-22
  • 打赏
  • 举报
回复
di应该加2。
cnzdgs 2009-02-22
  • 打赏
  • 举报
回复
mov [di],11101001b ; []前面没有加BYTE PTR啊!
imur2008 2009-02-22
  • 打赏
  • 举报
回复
不好意思,之前测试忘记在masm611测试(只在masmplus 1.2下测试)在masm611下面还是出错:

Y:\MASM611\BIN>ml m5.asm
Microsoft (R) Macro Assembler Version 6.11
Copyright (C) Microsoft Corp 1981-1993. All rights reserved.

Assembling: m5.asm
m5.asm(39): error A2070: invalid instruction operands

完整的源代码是:

.model small
.stack 200h
.code

testproc proc
mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3)
int 10h ; do it!

; cancel blinking and enable all 16 colors:
mov ax, 1003h
mov bx, 0
int 10h

; set segment register:
mov ax, 0b800h
mov ds, ax

; print "hello world"
; first byte is ascii code, second byte is color code.

mov BYTE PTR [SI+02h],'H';如果直接用立即数给内存赋值,编译器不知道该按哪种类型(BYTE、WORD等)来处理,BYTE PTR就是告诉编译器按字节处理。
mov BYTE PTR [SI+06h],'e'
mov BYTE PTR [SI+0ah],'l'
mov BYTE PTR [SI+0eh],'l'
mov BYTE PTR [SI+12h],'o'
mov BYTE PTR [SI+16h],','
mov BYTE PTR [SI+1ah],'W'
mov BYTE PTR [SI+1eh],'o'
mov BYTE PTR [SI+22h],'r'
mov BYTE PTR [SI+26h],'l'
mov BYTE PTR [SI+2ah],'d'
mov BYTE PTR [SI+2eh],'!'

; color all characters:
mov cx, 12 ; number of characters.
mov di, 03h ; start from byte after 'h'

s:
mov [di],11101001b ;11100001b ;11101100b
add di,4
loop s
; wait for any key press:
mov ah, 0
int 16h

ret
testproc endp

start:
call testproc
mov ah,4ch
int 21h
end start

另外,add di,4;请问这个为什么要将原来是add di,2改成add di,4?
willflyz 2009-02-21
  • 打赏
  • 举报
回复
我试了一下可以,不过要修改一下;

.model small
.stack 200h
.CODE

testproc proc
org 100h
mov ax, 3
int 10h
mov ax, 1003h
mov bx, 0
int 10h
; set segment register:
mov ax, 0b800h
mov ds, ax
mov si,0
mov [SI+02h],'H'
mov [SI+06h],'e'
mov [SI+0ah],'l'
mov [SI+0eh],'l'
mov [SI+12h],'o'
mov [SI+16h],','
mov [SI+1ah],'W'
mov [SI+1eh],'o'
mov [SI+22h],'r'
mov [SI+26h],'l'
mov [SI+2ah],'d'
mov [SI+2eh],'!'
mov cx, 12 ; number of characters.
mov di, 03h ; start from byte after 'h'
s:
mov [di],11101001b ;11100001b ;11101100b
add di,4
loop s
mov ah,0
int 16h
ret
testproc endp

START:
call testproc
mov ah,4ch
int 21h
END START
cnzdgs 2009-02-21
  • 打赏
  • 举报
回复
如果直接用立即数给内存赋值,编译器不知道该按哪种类型(BYTE、WORD等)来处理,BYTE PTR就是告诉编译器按字节处理。
按照上面写法,函数(开头)地址是0,如果后面再写org 100h,表示后面的代码从100h地址开始,中间100h未定义,由编译器来填充,一般都填00,调用函数时,会先执行这段代码,每两个00是一条add [bx+si],al指令。
imur2008 2009-02-21
  • 打赏
  • 举报
回复
在cnzdgs 大侠指点下,终于找到问题所在了

请问为什么要那么改?
我发现“所有[]前面都要加BYTE PTR 。”这个就可以了,那个“org 100h 去掉。 ”去掉或者不去掉都是可以的

请问老大说“org 100h 去掉。 ”这个为什么要去掉?
谢谢先
xzdgy 2009-02-21
  • 打赏
  • 举报
回复
帮顶
sizemismatch 2009-02-21
  • 打赏
  • 举报
回复
友情up
cnzdgs 2009-02-21
  • 打赏
  • 举报
回复
所有[]前面都要加BYTE PTR 。
org 100h 去掉。
imur2008 2009-02-21
  • 打赏
  • 举报
回复
谢谢老大指点!!!
这个代码,我在masmplus1.2的dos工程,可以调试通过

但是在masm611下面,ml m4.asm
出现错误:



Y:\MASM611\BIN>ml m4.asm
Microsoft (R) Macro Assembler Version 6.11
Copyright (C) Microsoft Corp 1981-1993. All rights reserved.

Assembling: m4.asm
m4.asm(16): error A2070: invalid instruction operands
m4.asm(17): error A2070: invalid instruction operands
m4.asm(18): error A2070: invalid instruction operands
m4.asm(19): error A2070: invalid instruction operands
m4.asm(20): error A2070: invalid instruction operands
m4.asm(21): error A2070: invalid instruction operands
m4.asm(22): error A2070: invalid instruction operands
m4.asm(23): error A2070: invalid instruction operands
m4.asm(24): error A2070: invalid instruction operands
m4.asm(25): error A2070: invalid instruction operands
m4.asm(26): error A2070: invalid instruction operands
m4.asm(27): error A2070: invalid instruction operands
m4.asm(31): error A2070: invalid instruction operands

请问是什么回事?

谢谢先
imur2008 2009-02-20
  • 打赏
  • 举报
回复
老大来了啊
那就是在masmPlus的dos工程吧
我现在在那个emu8086看到这个例子,但是不会改成dos下的汇编

请教请教,谢谢先
cnzdgs 2009-02-20
  • 打赏
  • 举报
回复
这是DOS程序,没法编译成Win32程序。

21,500

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧