之间&QUOT差异,MOV EAX,[NUM] QUOT;和" MOV EAX,NUM" [英] Difference between "mov eax, [num]" and "mov eax, num"

查看:287
本文介绍了之间&QUOT差异,MOV EAX,[NUM] QUOT;和" MOV EAX,NUM"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是初学者,写汇编程序使用此code 1打印编号,以9:

I am a beginner and writing assembly program to print numbers from 1 to 9 using this code:

section .text    
   global _start                    
_start:                     
   mov ecx,10    
   mov eax, '1'     
l1:    
   mov [num], eax    
   mov eax, 4    
   mov ebx, 1    
   push ecx     
   mov ecx, num            
   mov edx, 1            
   int 0x80     
   mov eax, [num]    
   sub eax, '0'    
   inc eax    
   add eax, '0'    
   pop ecx    
   loop l1      
   mov eax,1             ;system call number (sys_exit)    
   int 0x80              ;call kernel    
section .bss    
num resb 1

下面,我们有以下三个语句:

Here we have following three statements:


  1. MOV [NUM],EAX

  2. MOV ECX,NUM

  3. MOV EAX,[NUM]

我想知道为什么我们应该使用 MOV ECX,NUM ,而不是 MOV ECX,[NUM]

I want to know why we should use mov ecx,num rather than mov ecx,[num]

推荐答案

如果你熟悉C / C ++,这里是一个解释。

If you are familiar with C/C++, here is an explanation.

MOV ECX,NUM 等价于:

int num;
ecx = & num;


,而 MOV ECX,[NUM] 等价于:

int num;
ecx = num;


下面,该行的原因 MOV ECX,NUM 是因为你调用系统功能 INT 0x80的 ,这就要求 ECX 包含你的号码的地址。因此,它应该是这样的。


Here, the reason for the line mov ecx, num is because you are calling the system function int 0x80, which requires that ecx contains the address of your numbers. So it should be like that.

这篇关于之间&QUOT差异,MOV EAX,[NUM] QUOT;和" MOV EAX,NUM"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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