【发布时间】:2016-01-05 01:22:21
【问题描述】:
public static void main(String[] args) {
int a = 0;
for (int i = 0; i < 20; i++) {
if (i < 10) {
a++;
} else {
a--;
}
}
System.out.println(a);
System.exit(0);
}
这是我要翻译成汇编代码的代码。我认为除了 system.out.println(a);
我几乎尝试了所有方法,包括对 sys_write 调用的各种输入。我不允许使用 print f,而应该使用 mov 命令。这是我现在的代码:
cr equ 13
ld equ 10
STDOUT equ 1
SYS_WRITE equ 4
section .bss
a resb 1
section .text
global _start
_start:
mov [a], byte 0
mov [a],ax
start_for:
cmp cx,20
jge slutt_for
cmp cx,10
jge else
inc ax
jmp slutt_if
else:
dec ax
slutt_if:
inc cx
jmp start_for
slutt_for:
mov ecx,eax ; This is where I need help
add ecx,'0'
mov eax,4
mov edx,5
mov ebx,1
int 80h ; End where I need help
mov eax,1
int 80h
它应该在我使用 gdb -tui filename 访问的调试器中工作,但没有任何结果。其余的代码做它应该做的,但不是输出。我几乎什么都试过了。帮忙?
【问题讨论】:
标签: java linux assembly printf nasm