首页
社区
课程
招聘
[求助]下面的代码,可以在emu8086模拟器可以运行,请问怎么才能在masm32或者masmplus运行?
发表于: 2009-2-20 21:47 6684

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

2009-2-20 21:47
6684
下面的代码,可以在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

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (10)
雪    币: 2067
活跃值: (82)
能力值: ( LV9,RANK:180 )
在线值:
发帖
回帖
粉丝
2
你好像研究一阵子类似的东西了
建议你弄台便宜的电脑单纯装DOS
2009-2-20 22:43
0
雪    币: 2110
活跃值: (21)
能力值: (RANK:260 )
在线值:
发帖
回帖
粉丝
3
32位程序使用Windows的系统服务,16位代码使用DOS的系统服务,是完全不同的。

DOS的系统调用是int 0x21,而Windows的系统服务主要是通过命名的API接口提供的。

所以,这里不是简单地改写的问题,而是完全重写的问题。

32位控制台输出字串,使用msvcrt中上printf比较方便。至于颜色控制,则是个比较复杂的过程。简单地说,涉及到GetStdHandle、SetConsoleScreenBufferInfoEx等API函数。
2009-2-20 22:56
0
雪    币: 2110
活跃值: (21)
能力值: (RANK:260 )
在线值:
发帖
回帖
粉丝
4
忘了重要的SetConsoleTextAttribute
2009-2-20 23:03
0
雪    币: 2067
活跃值: (82)
能力值: ( LV9,RANK:180 )
在线值:
发帖
回帖
粉丝
5
标题本身就有问题了
2009-2-20 23:11
0
雪    币: 40
活跃值: (18)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
谢谢2位老大的指点
是怪我没有说清楚,应该是说在吗修改才能在dos下使用masm611等运行
这个是dos汇编,是emu8086的例子,但是在emu8086下可以运行,我复制出来在masmplus下的dos工程不能运行

不知是什么问题

请教请教

另:我电脑安装了纯dos

谢谢先
2009-2-20 23:26
0
雪    币: 1596
活跃值: (25)
能力值: ( LV7,RANK:110 )
在线值:
发帖
回帖
粉丝
7
这种问题应该找王爽问问
2009-2-21 15:55
0
雪    币: 231
活跃值: (45)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
qdk
8
直接编译,保存成 t.asm
命令行下
set path=XXXX(你的masm的地址)
ml t.asm
得到exe之后直接执行就可以看到结果了。
代码里的两个操作在ntvdm里都有模拟的
2009-2-22 03:00
0
雪    币: 40
活跃值: (18)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
直接编译,保存成 t.asm???
请问这个是不是写错了,应该是“直接保存成t.asm”吧?
要是这样,我编译,出错:
t.asm(45): error A2034: must be in segment block                              
t.asm(46): error A2034: must be in segment block                              
t.asm(51): error A2034: must be in segment block                              
t.asm(53): error A2034: must be in segment block                              
t.asm(55): error A2034: must be in segment block                              
t.asm(57): error A2034: must be in segment block                              
t.asm(59): error A2034: must be in segment block                              
t.asm(61): error A2034: must be in segment block                              
t.asm(63): error A2034: must be in segment block                              
t.asm(65): error A2034: must be in segment block                              
t.asm(67): error A2034: must be in segment block                              
t.asm(69): error A2034: must be in segment block                              
t.asm(71): error A2034: must be in segment block                              
t.asm(73): error A2034: must be in segment block                              
t.asm(79): error A2034: must be in segment block                              
t.asm(80): error A2034: must be in segment block                              
t.asm(82): error A2008: syntax error : c                                       
t.asm(83): error A2034: must be in segment block                              
t.asm(84): error A2008: syntax error : c                                       
t.asm(87): error A2034: must be in segment block                              
t.asm(88): error A2034: must be in segment block                              
t.asm(90): error A2034: must be in segment block                              
t.asm(90): error A2088: END directive required at end of file                  
                                                                              
请问有什么最简单的办法?
2009-2-22 05:31
0
雪    币: 231
活跃值: (45)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
qdk
10
这还不够简单吗
.586p
code_seg segment use16
org 100h
start:
      xxxxx加入你的代码
code_seg ends
start end
2009-2-22 05:49
0
雪    币: 40
活跃值: (18)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11
xxxxx加入你的代码
===请问老大,这个地方的“你的代码”是不是指:; 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

我将这个代码复制进去,masmplus 1.2(按照masm32编译)和masm611编译,都是出错:
masm611提示错误:

                                                                              
Y:\MASM611>cd bin                                                              
                                                                              
Y:\MASM611\BIN>ml t2.asm                                                      
Microsoft (R) Macro Assembler Version 6.11                                    
Copyright (C) Microsoft Corp 1981-1993.  All rights reserved.                  
                                                                              
Assembling: t2.asm                                                            
t2.asm(22): error A2001: immediate operand not allowed                        
t2.asm(23): error A2001: immediate operand not allowed                        
t2.asm(24): error A2001: immediate operand not allowed                        
t2.asm(25): error A2001: immediate operand not allowed                        
t2.asm(26): error A2001: immediate operand not allowed                        
t2.asm(27): error A2001: immediate operand not allowed                        
t2.asm(28): error A2001: immediate operand not allowed                        
t2.asm(29): error A2001: immediate operand not allowed                        
t2.asm(30): error A2001: immediate operand not allowed                        
t2.asm(31): error A2001: immediate operand not allowed                        
t2.asm(32): error A2001: immediate operand not allowed                        
t2.asm(33): error A2001: immediate operand not allowed                        
t2.asm(42): error A2070: invalid instruction operands                          
t2.asm(52): error A2008: syntax error : start                                 
t2.asm(52): error A2088: END directive required at end of file                 
                                                                              
masmplus1.2提示出错:
ml.exe /c /coff /nologo /Fo"t2.obj" "D:\XPshare\MASM611\BIN\t2.ASM"
Assembling: D:\XPshare\MASM611\BIN\t2.ASM
D:\XPshare\MASM611\BIN\t2.ASM(2): error A2210: 16 bit segments not allowed with /coff option
D:\XPshare\MASM611\BIN\t2.ASM(22): error A2001: immediate operand not allowed
D:\XPshare\MASM611\BIN\t2.ASM(23): error A2001: immediate operand not allowed
D:\XPshare\MASM611\BIN\t2.ASM(24): error A2001: immediate operand not allowed
D:\XPshare\MASM611\BIN\t2.ASM(25): error A2001: immediate operand not allowed
D:\XPshare\MASM611\BIN\t2.ASM(26): error A2001: immediate operand not allowed
D:\XPshare\MASM611\BIN\t2.ASM(27): error A2001: immediate operand not allowed
D:\XPshare\MASM611\BIN\t2.ASM(28): error A2001: immediate operand not allowed
D:\XPshare\MASM611\BIN\t2.ASM(29): error A2001: immediate operand not allowed
D:\XPshare\MASM611\BIN\t2.ASM(30): error A2001: immediate operand not allowed
D:\XPshare\MASM611\BIN\t2.ASM(31): error A2001: immediate operand not allowed
D:\XPshare\MASM611\BIN\t2.ASM(32): error A2001: immediate operand not allowed
D:\XPshare\MASM611\BIN\t2.ASM(33): error A2001: immediate operand not allowed
D:\XPshare\MASM611\BIN\t2.ASM(42): error A2070: invalid instruction operands
D:\XPshare\MASM611\BIN\t2.ASM(52): error A2008: syntax error : start
D:\XPshare\MASM611\BIN\t2.ASM(52): error A2088: END directive required at end of file

请问怎么办?请教请教
2009-2-22 08:46
0
游客
登录 | 注册 方可回帖
返回
//