首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有windows api的NASM中的hello world

没有windows api的NASM中的hello world
EN

Stack Overflow用户
提问于 2014-04-03 14:00:25
回答 2查看 2.5K关注 0票数 2

我一直在使用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:

代码语言:javascript
复制
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 

希望我没有模棱两可:)

EN

回答 2

Stack Overflow用户

发布于 2014-04-11 22:29:14

我喜欢从vitsoft中学习上面的代码的一些变化,而不是使用软件中断将字符串直接打印到我们必须在下面的代码中指定的给定屏幕坐标。(但它不会接触或移动coursor位置。)对于64位Windows,请使用DOSBOX。

代码语言:javascript
复制
; 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
票数 2
EN

Stack Overflow用户

发布于 2014-04-03 20:41:40

如果DOS功能还不够简单,您可以使用PC固件中硬连接的BIOS功能。在http://www.ctyme.com/rbrown.htm的Ralf Brown的中断列表中记录了这些问题

代码语言:javascript
复制
; 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 program
票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22829044

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档