바보처럼 들리 겠지만 어셈블리 언어는 처음이에요.어셈블리에서 '변수'레이블에 jmp가 있음 (AT & T 구문)
다음 코드는 내가 수행하려고 시도했던 것의 단순화 된 버전입니다.
1 # print.s
2 # C callable: char* print()
3
4 .data
5 output:
6 .asciz "abcd"
7
8 .text
9 .globl _printbin
10
11 _printbin:
12 pushl %ebp # set up stack frame
13 movl %esp, %ebp # save esp in ebp
14
15 movl $output, %eax # put the address of "abcd" in eax
16
17 xor %ebx, %ebx # clear ebx
18 movl $5, %ebx # put 5 in ebx (input for func)
19 movl $0, %edx # put 1 in edx (index)
20 jmp _func # call func
21
22 back1:
23 xor %ebx, %ebx # clear ebx
24 movl $7, %ebx # put 7 in ebx (input for func)
25 movl $2, %edx # put 2 in edx (index)
26 jmp _func # call func
27
28 end:
29 movl %ebp, %esp # restore esp
30 popl %ebp # restore ebp
31 ret
32
33 # take the input, add 1 to it,
34 # then print it to eax at the specified index
35 _func: # num input in %ebx, index is in %edx , print to: %eax
36 addb $0x1, %ebx # print the result to eax
37 movb %ebx, (%eax, %edx)
38 jmp back1 # how to decide wether to jump to back1 or to end?
39
40 .end
41
"가변적 인"레이블로 어떻게 이동할 수 있습니까? (때로는이 레이블로 점프하고 싶지만 다른 레이블은 ... 그런 종류의 아이디어입니다.)
왜 36, 37 행에서'addb'와'movb'를 사용하고 있습니까? 만약 내가 잘못하지 않았다면 이것은'addl'과'movl'이어야합니다; 'b' 접미사는'bytes'를위한 것입니다 – Hawken