我一直在使用NASM在Linux上编写汇编代码,现在正在尝试学习Windows上的同样方法。遵循Ray Duncan的高级MS-DOS编程,图3-7列出了一个基于MASM的hello world程序,它基本上使用中断21h打印"hello world“。这与在Linux上使用interrupt 80h做同样的事情是同义的,感觉就像家一样。我想在windows上使用NASM做同样的事情。
网络上的大多数示例都使用Windows API,如_GetStdHandle、_WriteConsoleA等,或使用C库,如_printf。我想在下面的代码片段中直接使用bones.Something:
global _start
section .data
str: db 'hello, world',0xA
strLen: equ $-str
section .text
_start:
mov ah,40h
mov bx,1
mov cx, strLen
mov dx, str
int 21h
mov ax,4c00h
int 21h 希望我没有模棱两可:)
发布于 2014-04-11 22:29:14
我喜欢从vitsoft中学习上面的代码的一些变化,而不是使用软件中断将字符串直接打印到我们必须在下面的代码中指定的给定屏幕坐标。(但它不会接触或移动coursor位置。)对于64位Windows,请使用DOSBOX。
; Save as hello.asm, assemble with nasm -f bin -o hello.com hello.asm
ORG 256
Start: JMP Main
strOfs DB 'hello, world'
strLen EQU $-strOfs ; meaning of $ = offset address of this position in the code
Main: MOV SI,strOfs ; offset address of the string
MOV CX,strLen ; lenght of the string
MOV AX, 0B800h ; segment address of the textmode video buffer
MOV ES, AX ; store the address in the extra segment register
MOV DI, (Line_Number*80*2)+(Row_number*2) ; target address on the screen
CLD ; let the pointer adjustment step forward for string instructions
nextChar: LODSB ; load AL from DS:[SI], increment SI
STOSB ; store AL into ES:[DI], increment DI
INC DI ; step over attribute byte
LOOP nextChar ; repeat until CX=0
MOV AH,00h ; BIOS function GET KEYSTROKE
INT 16h ; Press any key to continue
RET ; Exit program发布于 2014-04-03 20:41:40
如果DOS功能还不够简单,您可以使用PC固件中硬连接的BIOS功能。在http://www.ctyme.com/rbrown.htm的Ralf Brown的中断列表中记录了这些问题
; Save as hello.asm, assemble with nasm -f bin -o hello.com hello.asm
ORG 256
Start: JMP Main
strOfs DB 'hello, world',0Ah
strLen EQU $-strOfs
Main: MOV SI,strOfs
MOV CX,strLen
SUB BX,BX ; clear videopage number and color
MOV AH,0Eh ; BIOS function TELETYPE OUTPUT
CLD
nextChar: LODSB ; load AL from [SI], increment SI
INT 10h ; Display one character, advance cursor position
LOOP nextChar
MOV AH,00h ; BIOS function GET KEYSTROKE
INT 16h ; Press any key to continue
RET ; Exit programhttps://stackoverflow.com/questions/22829044
复制相似问题