我想得到我的教程汇编程序的退出代码(使用masm32和链接).它工作正常,我会输入echo %errorlevel%,它会显示我输入的退出代码invoke ExitProcess.现在它不再起作用了.我在OpenSuse 12.1主机和Windows Vista Home Premium上使用VirtualBox作为访客.我已经找到了答案,但已经缩短了.大多数抱怨是关于使用批处理文件,这不是我想要做的.这是一个简单的程序
hello_world.asm
.586
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
.data
HelloWorld db "Hello World!", 0
.code
start:
invoke MessageBox, NULL, addr HelloWorld, addr HelloWorld, MB_OK
invoke ExitProcess, 2
end start
Run Code Online (Sandbox Code Playgroud)
我希望它返回2,但echo %errorlevel%返回0.有什么我想念的吗?谢谢,我道歉这个问题已经被解决了.我找不到答案.
编辑:实际上,我找到了部分答案.它只适用于我链接使用/SUBSYSTEM:CONSOLE.使用/SUBSYSTEM:WINDOWS始终返回0.我不知道该怎么做.带有Windows程序的退出代码在哪里?任何信息非常感谢.
C编译器如何向函数传递/返回struct/union?在函数调用之前是否将结构推送到堆栈只是传递给函数的struct的引用?
同样的问题适用于退货.函数返回的是什么?
typedef struct {
long m4;
long m3;
long m2;
long m1;
} ext_components_t;
typedef union {
long array[sizeof(int_components_t)];
int_components_t comp;
} int_components_u;
typedef union {
long array[sizeof(ext_components_t)];
ext_components_t comp;
} ext_components_u;
#pragma never_inline
ext_components_u transfer(int_components_u m)
{
ext_components_u out;
out.comp.m1 = 10*m.comp.a+11*m.comp.b+12*m.comp.c;
out.comp.m2 = 20*m.comp.a+21*m.comp.b+22*m.comp.c;
out.comp.m3 = 30*m.comp.a+31*m.comp.b+32*m.comp.c;
out.comp.m4 = 40*m.comp.a+41*m.comp.b+42*m.comp.c;
return out;
}
volatile int_components_u x;
volatile ext_components_u y;
void main()
{
y = transfer(x);
}
Run Code Online (Sandbox Code Playgroud)
这是我的猜测(伪代码):
push_stack(x.array[0])
push_stack(x.array[1])
push_stack(x.array[2])
call transfer
y.array[0] = shift_stack()
y.array[1] = …Run Code Online (Sandbox Code Playgroud) 我在C中制作了一个冒泡排序程序,并检查了它的汇编列表文件.但我无法得到for循环的位置.你能让我知道for循环和if语句在哪里?
#include<stdio.h>
int main()
{
int arr[5]={2,4,5,6,1};
int i,j,tmp;
for(i=0;i<5;i++)
{
for(j=0;j<4;j++)
{
if(arr[j]>arr[j+1])
{
tmp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=tmp;
}
}
}
for(i=0;i<5;i++){
printf(" %d",arr[i]);
}
printf("\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这里是汇编列表文件.
; generated by ARM C Compiler, ADS1.2 [Build 848]
; commandline [-O1 -browseinfo "0xff
" -S -g+ -fk -J:cw:]
CODE32
AREA ||.text||, CODE, READONLY
main PROC
|L1.0|
STMFD sp!,{r4,lr}
SUB sp,sp,#0x18
MOV r2,#0x14
LDR r1,|L1.148|
ADD r0,sp,#4
BL __rt_memcpy_w
MOV r12,#0
|L1.28|
MOV r0,#0
|L1.32|
ADD r1,sp,#4
ADD r2,sp,#4
ADD …Run Code Online (Sandbox Code Playgroud) 我尝试编写一个汇编程序,它的输入数字为 4 的幂。它会循环并将 %eax 当前值与原始输入数字相乘,直到它在 %ecx 值为 0 时跳转到完成。
但是程序运行后它返回0。我不确定为什么(?),是否返回了 %ecx 寄存器值而不是 %eax?
当有多个寄存器使用其中的值时,关于返回什么的规则是什么?
.globl funk
.globl _funk
funk:
_funk:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %edx
movl $1, %eax
movl $4, %ecx
jmp check
check:
cmpl $0, %ecx
jz done
jmp multiply
done:
popl %ebp
ret
multiply:
mull %edx
dec %ecx
jmp check
Run Code Online (Sandbox Code Playgroud) 如何使用 Delphi 的内联汇编器获取数字的位数?
例如 :
13452 should return 5
1344 should return 4
9721343 should return 7
Run Code Online (Sandbox Code Playgroud)
等等
我的尝试是这样的:
function CalculateLength(Number : integer) : Integer;
begin
asm
PUSH Length(Number)
MOV @Result, EAX
end;
end;
Run Code Online (Sandbox Code Playgroud) 以下是我在汇编中的代码,将源数组的内容复制到目标数组.但似乎源数组的所有内容都没有复制到目标数组.请帮忙.
INCLUDE Irvine32.inc
.data
mess1 byte "YOUR ARRAY IS:",0
mess2 byte "COPIED Array is:",0
source byte "YOU Have to work hard to score a 4",0
target byte sizeof source dup(0)
.code
main PROC
call clrscr
call crlf
mov edx,offset mess1
call writestring
call crlf
mov edx,offset source
call writestring
call crlf
call crlf
mov ecx,sizeof source
L1:
mov esi,0
mov al,source[esi]
mov target[esi],al
inc esi
loop L1
mov edx,offset mess2
call writestring
call crlf
mov edx,offset target
call writestring
exit …Run Code Online (Sandbox Code Playgroud) 如何使用Assembly与Masm32随机分配数字?如何创建随机数生成器?
非常感谢你!