c++

c++ 어셈블리어 간단하게 공부

이야기prog 2025. 2. 22. 22:32
%include "io64.inc"
section .text
global main
main:
    mov rbp, rsp; for correct debugging
    ;write your code here
    ;1~100사이 값중 홀수면 1 짝수면 0출력
    GET_DEC 1, a
    mov bl, 1
    and [a], bl
    cmp [a], byte 1
    je LABEL_EQUAL
    
    PRINT_DEC 1, 0
    jmp LABEL_NOT_EQUAL
LABEL_EQUAL:
    PRINT_DEC 1, 1
    
LABEL_NOT_EQUAL:
    xor rax, rax
    ret



section .bss
    g resb 10 ; 변수이름 크기 개
    a resb 1

SASM 프로그램으로 간단하게 홀수 짝수 구분을 어셈블리어로 풀어보았다.

 

%include "io64.inc"
section .text
global main
main:
    mov rbp, rsp; for correct debugging
    ;write your code here
    mov ecx, 10
    
LABEL_LOOP:
    PRINT_STRING msg
    NEWLINE
    dec ecx
    cmp ecx, 0
    jne LABEL_LOOP
        

    xor rax, rax
    ret
section .data
    msg db "Hello World", 0x00


section .bss
    g resb 10 ; 변수이름 크기 개
    a resb 1

SASM 프로그램에서 반복문을 만드는 방법을 작성해보았다. "Hello World" 10번 출력

 

%include "io64.inc"
section .text
global main
main:
    mov rbp, rsp; for correct debugging
    ;write your code here
    mov eax, 1
    
LABEL_LOOP:
    add [a], eax
    inc eax ; inc = +1, dec = -1
    cmp eax, 100
    jle LABEL_LOOP    
   
    PRINT_DEC 4, [a]
    xor rax, rax
    ret
section .data
    ;msg db "Hello World", 0x00
    a dd 0


section .bss
   ; g resb 10 ; 변수이름 크기 개

1부터 100까지 합하는 코드

 

 

'c++' 카테고리의 다른 글

c++ 공부  (0) 2025.02.27
c++공부  (0) 2025.02.24
c++ 공부  (0) 2025.02.12
c++ 공부  (0) 2025.01.30
c++ 공부  (0) 2025.01.29