访问nasm中子程序内的全局字符串 [英] access global strings inside sub-programs in nasm

查看:75
本文介绍了访问nasm中子程序内的全局字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



作为汇编语言的初学者,我要做的就是在汇编程序中访问全局声明的字符串并按字符打印其内容(现在我试图打印只有第一个字符......用于测试目的)但是出了问题。你能指导我吗。



环境:nasm,16位,Intel X86,平板组装商



代码片段供您参考。

请注意,我没有粘贴整个代码供您参考。它只是我知道的一些子程序部分是错误的。

Hi,
As a very beginner to assembly language all I am trying to do is to access a globally declared string in assembly program and print its content character by character( for now i m trying to print only first character...for testing purpose) but something is really going wrong. Could you please guide me.

Environment: nasm, 16 bit, Intel X86, flat assembler

Code snippet for your reference.
Please note that I have not pasted the entire code for your reference. Its only the subroutine part that I know something is wrong.

MsgX: db "Hello World!", 0x00

prints:
   push bp
   mov  bp, sp
   sub  sp, 2

   push word MsgX
   mov  bx, [bp-2]
   mov  al, byte [bx]
   mov  ah, 0x000E
   int  0x0010
ret

main:
   call prints





请帮助:)

任何16位的例子或代码片段都是可以理解的。



Please help :)
Any examples or code snippets in 16 bit would be appreciable.

推荐答案

这是实模式的解决方案,DOS(需要使用 int 0x21 ,这是DOS系统调用): http://montcs.bloomu.edu/Code/Asm.and.C/Asm.Nasm/hello- in-assembly.shtml [ ^ ]。



如果不是这样,请提供有关您的详细信息平台;请看我对这个问题的评论。



您可以根据所使用的CPU型号信息和内存模型(例如英特尔)进行大量计算,在某种程度上与平台无关,但如果涉及I / O,则无法执行此操作,例如屏幕输出。例如,除非您使用某种虚拟PC解决方案的模拟器,否则上面引用的代码在Windows / * NIX等中不起作用。例如,使用DOS,您可以使用系统服务软件中断调用,或者以文本或视频模式直接访问视频内存。两种方式都取决于平台信息。



这不是你关于汇编编程的第一个问题,但你仍然没有提供全面的信息。



-SA
This is the solution for real mode, DOS (required to use int 0x21, which is the DOS "system call"): http://montcs.bloomu.edu/Code/Asm.and.C/Asm.Nasm/hello-in-assembly.shtml[^].

If this is not it, please provide further detail on your platform; please see my comment to the question.

You could do a lot of calculations based on just the CPU model information and memory model used (for Intel, for example), in a way agnostic to the platform, but you cannot do it if I/O is involved, such as screen output. For example, the code referenced above won''t work in Windows/*NIX and the like, unless you use some kind of emulator of virtual PC solution. With DOS, for example, you could use either use the system service software interrupt "call", or directly access video memory in its text or video mode. Both ways would depend on platform information.

This is not your first question on assembly programming, but you still did not provide comprehensive information.

—SA


这篇关于访问nasm中子程序内的全局字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆