【发布时间】:2012-10-01 20:08:35
【问题描述】:
作为 ASM 编程的初学者,我需要在 Assembly 中获得 2 的 38 次方的结果,并且我需要您的帮助来理解为什么我的程序没有产生我需要的结果(它打印 4十进制):
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\msvcrt.inc
includelib \masm32\lib\msvcrt.lib
.data
formatstr db "%d",0
.code
start:
mov eax , 2
mov ecx , 38
mov esi , eax
mov edx , 0
.while TRUE
mul esi
mov esi, edx
add esi, eax
mov edx, 0
mov eax, 2
dec ecx
.break .if (!ecx)
.endw
invoke crt__cprintf, addr formatstr, esi
end start
如您所见,我正在使用 masm32 编写它(如果在这种情况下有任何问题)。
【问题讨论】:
-
想一想存储 2^38 需要多少位以及结果寄存器需要多少位。
-
请注意,2^38 对于(32 位)int 来说太大了 - 您的 printf 格式字符串需要是 %lld,而不是 %d,并且相应的参数需要是 64 位。
标签: assembly x86 masm exponent exponentiation