从编译的.ASM文件执行.exe文件后,在命令行中显示文本

发布于 2025-02-06 23:31:25 字数 1671 浏览 1 评论 0原文

这可能是一个愚蠢的问题,但我是汇编编程的新手,我已经将包含以下汇编源代码的文件转换为.exe文件。该代码取自 httpps://www.tutorialspoint.com/assembly_comembly_programmbly_masembly_mmannection a>顺便说一句。

section .text
   global _main         ;must be declared for using gcc
    
_main:                   ;tell linker entry point

   mov  eax, 45      ;sys_brk
   xor  ebx, ebx
   int  80h

   add  eax, 16384   ;number of bytes to be reserved
   mov  ebx, eax
   mov  eax, 45      ;sys_brk
   int  80h
    
   cmp  eax, 0
   jl   exit    ;exit, if error 
   mov  edi, eax     ;EDI = highest available address
   sub  edi, 4       ;pointing to the last DWORD  
   mov  ecx, 4096    ;number of DWORDs allocated
   xor  eax, eax     ;clear eax
   std           ;backward
   rep  stosd            ;repete for entire allocated area
   cld           ;put DF flag to normal state
    
   mov  eax, 4
   mov  ebx, 1
   mov  ecx, msg
   mov  edx, len
   int  80h      ;print a message

exit:
   mov  eax, 1
   xor  ebx, ebx
   int  80h
    
section .data
msg     db  "Allocated 16 kb of memory!", 10
len     equ $ - msg

然后,我在命令行中运行以下代码,并且没有确认输出: 命令行nasm和gcc命令

如果我在在线编译器中运行它,我会得到一个确认消息“分配了16 kb的内存!”,而命令行中没有任何消息。我想念什么吗?或我应该添加什么。怎么知道是否分配了16KB?我已经摆弄了以前的查询,但我仍然不知道:在32位Windows上的NASM中创建一个EXE文件。我希望这是有道理的。

This might be a dumb question but I'm new to assembly programming and I've converted a .asm file containing the following assembly source code to a .exe file. The code was taken from https://www.tutorialspoint.com/assembly_programming/assembly_memory_management.htm by the way.

section .text
   global _main         ;must be declared for using gcc
    
_main:                   ;tell linker entry point

   mov  eax, 45      ;sys_brk
   xor  ebx, ebx
   int  80h

   add  eax, 16384   ;number of bytes to be reserved
   mov  ebx, eax
   mov  eax, 45      ;sys_brk
   int  80h
    
   cmp  eax, 0
   jl   exit    ;exit, if error 
   mov  edi, eax     ;EDI = highest available address
   sub  edi, 4       ;pointing to the last DWORD  
   mov  ecx, 4096    ;number of DWORDs allocated
   xor  eax, eax     ;clear eax
   std           ;backward
   rep  stosd            ;repete for entire allocated area
   cld           ;put DF flag to normal state
    
   mov  eax, 4
   mov  ebx, 1
   mov  ecx, msg
   mov  edx, len
   int  80h      ;print a message

exit:
   mov  eax, 1
   xor  ebx, ebx
   int  80h
    
section .data
msg     db  "Allocated 16 kb of memory!", 10
len     equ $ - msg

I then ran the following codes in the command line and got no confirmation output:
command line NASM and GCC commands

If I run it in an online compiler, I'm getting a confirmation message "Allocated 16 kb of memory!", whereas no message was prompted in the command line. Am I missing something? or what should I add. How will a know if 16kb was allocated? I've fiddled with this previous query but I still don't know how: Create an exe file in assembly with NASM on 32-bit Windows. I hope this makes sense.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文