Tuuna Computer Science

[어셈블리어] 구구단 출력하기 본문

Assembly

[어셈블리어] 구구단 출력하기

GuTTe 2018. 8. 30. 01:06

물론 형편없는 코드지만 공부용으로 작성 ~


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
%include "asm_io.inc"
    extern printf
 
segment .data
    format db "%d x %d = %d"0
    hello db "Hello this is a group of game"0
 
segment .bss
    input resd 0; 합을 저장할 변수
 
 
segment.text
    global asm_main
 
asm_main :
    enter 40    
    pusha
 
    push hello
    call printf
    add esp, 4
    call print_nl
    mov eax1; i
    mov ebx1; j
 
gugu_eax_loop :
    mov ebx1
    cmp eax10
    jg gugu_loop_end
 
 
gugu_ebx_loop :
    cmp ebx10
    jg setting_eax
 
    push eax
    imul eaxebx    
    mov [input], eax; backup output
    pop eax
 
    mov[ebp - 4], eax
    push dword[input]
    push ebx
    push eax
    push format
    call printf; 반환값이 eax에 쌓이넹
    mov eax[ebp - 4]
    add esp, 16
    call print_nl
 
    inc ebx
    jmp gugu_ebx_loop
 
setting_eax :
    inc eax
    call print_nl
    jmp gugu_eax_loop
 
gugu_loop_end :    
    popa
    leave
    ret
cs


코드 작성하면서 gdb는 gdb인것 같다. 또 어셈블리로 코드를 작성하다보니 gdb에서 보니 편하기도 하고...


작성하면서 bss영역에 초기화중 store변수와 input변수의 주소가 겹치던데 왜 그런걸까

Comments