我一直在研究这个程序,我必须输入一个字符串,然后在该字符串中显示字符分布.
例如:
如果输入是"minecode",则输出应为
C - 1
O - 1
D - 1
E - 2
I - 1
M - 1
N - 1
这是我试图做的,但我真的不知道如何遍历循环并检查相似的字符然后增加计数.汇编程序是在32位机器上运行的MASM 615.
.686
.MODEL flat, stdcall
.STACK
INCLUDE Irvine32.inc
.DATA
msg0 BYTE "Enter a string of characters: ",0
msg1 BYTE "Character Distribution: ",0
MainArray dword 10000 dup (?)
UniqueChar dword 10000 dup (?)
CharCount dword 10000 dup (?)
.CODE
MAIN PROC
lea edx, msg0
call WriteString
call dumpregs ; 1
call ReadString
mov MainArray, eax
call …Run Code Online (Sandbox Code Playgroud) 我收到此错误:
loop AdderLoop
Run Code Online (Sandbox Code Playgroud)
错误A2075:跳转目标太远:25个字节
这是一个加法器程序.
我还在学习pop,push所以也许我没有做正确的事,但似乎我的变量ARRAY_SIZE没有正确存储?
我在程序开始时按下存储ARRAY_SIZE的寄存器,并在程序结束时将其弹出.
.386 ;identifies minimum CPU for this program
.MODEL flat,stdcall ;flat - protected mode program
;stdcall - enables calling of MS_windows programs
;allocate memory for stack
;(default stack size for 32 bit implementation is 1MB without .STACK directive
; - default works for most situations)
.STACK 4096 ;allocate 4096 bytes (1000h) for stack
;*******************MACROS********************************
;mPrtStr
;usage: mPrtStr nameOfString
;ie to display a 0 terminated string named message say:
;mPrtStr message …Run Code Online (Sandbox Code Playgroud) 我正在尝试计算数组中有多少个数字 1。
首先我有一个 C lenguaje 代码(工作正常):
int popcount2(int* array, int len){
int i;
unsigned x;
int result=0;
for (i=0; i<len; i++){
x = array[i];
do{
result+= x & 0x1;
x>>= 1;
} while(x);
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
现在我需要使用 3-6 行代码将 do-while 循环转换为汇编。我写了一些代码,但结果不正确。(我是汇编世界的新手)
int popcount3(int* array, int len){
int i;
unsigned x;
int result=0;
for (i=0; i<len; i++){
x = array[i];
asm(
"ini3: \n"
"adc $0,%[r] \n"
"shr %[x] \n"
"jnz ini3 \n"
: [r]"+r" (result)
: [x] "r" (x) ); …Run Code Online (Sandbox Code Playgroud) 我编写了一个汇编程序来显示遵循 AT&T 语法的数字的阶乘。但它不起作用。这是我的代码
.text
.globl _start
_start:
movq $5,%rcx
movq $5,%rax
Repeat: #function to calculate factorial
decq %rcx
cmp $0,%rcx
je print
imul %rcx,%rax
cmp $1,%rcx
jne Repeat
# Now result of factorial stored in rax
print:
xorq %rsi, %rsi
# function to print integer result digit by digit by pushing in
#stack
loop:
movq $0, %rdx
movq $10, %rbx
divq %rbx
addq $48, %rdx
pushq %rdx
incq %rsi
cmpq $0, %rax
jz next
jmp loop
next:
cmpq $0, %rsi …Run Code Online (Sandbox Code Playgroud) 我正在用x86汇编语言(MASM32)为Windows编写一个简单的素性测试程序,它涉及计算(64位)整数的平方根.我的问题是:有没有简单的方法来获得平方根?我应该使用ADD/SUB/DIV/MUL指令的某些组合吗?
我找到了一些关于如何用C语言实现这一目标的信息,但我只是想知道我是否在这里遗漏了一些东西?
我了解的是,指令融合有两种类型:
微操作是指可以在1个时钟周期内执行的操作。如果几个微操作融合在一起,我们将获得一个“指令”。
如果融合了多条指令,我们将获得宏操作。
如果几个宏操作融合在一起,我们将获得宏操作融合。
我对么?
mov ecx, 16
looptop: .
.
.
loop looptop
Run Code Online (Sandbox Code Playgroud)
此循环执行多少次?
如果ecx = 0开始,会发生什么?loop在这种情况下会跳还是掉下去?
这是Irvine基于英特尔计算机的汇编语言练习:
在这个例子中,EAX的最终价值是多少?
mov eax,0
mov ecx,10 ; outer loop counter
L1:
mov eax,3
mov ecx,5 ; inner loop counter
L2:
add eax,5
loop L2 ; repeat inner loop
loop L1 ; repeat outer loop
Run Code Online (Sandbox Code Playgroud)
我的解决方案是eax = 28,因为最初的ecx设置为5,所以L2执行5次,因此eax = 3 + 5*5 = 28.然后ecx变为0并且流程移出L2,但由于ecx = 0,L1不会重复,它将移动到下一行而不重复L1.所以eax的最终值= 28.我知道这是错的,但有人能说出我的想法中的错误在哪里?