Skip to main content

18108 - 1998년생인 내가 태국에서는 2541년생?!

info

풀이 키워드

스포주의

구현


풀이 코드

info
  • 메모리: 4348 KB
  • 시간: 0 ms
default rel

global main
extern printf, scanf

section .data
scan_fmt: db "%d", 0
print_fmt: db "%d", 10, 0 ; %d\n

section .bss
d: resd 1 ; int

section .text

main:
push rbp
mov rbp, rsp

;--- input ---
mov rdi, scan_fmt
lea rsi, [d]
xor rax, rax
call scanf

;--- calc ---
mov eax, [d]
sub eax, 543

;--- output ---
mov rdi, print_fmt
mov rsi, rax
call printf

;--- cleanup ---
xor rax, rax
leave
ret

풀이 해설

심플하게 주어진 년도에서 543년 빼면 된다.


메모

  • 로컬에서 테스트할시 gcc 플래그에 -no-pie 추가하십쇼
  • 백준 환경에선 naked로 작성해도 되고, scanf AL 레지스터도 초기화 생략 가능한듯 (impl dependent)
    • SEGV 터지면 초기화해야 함. 대표적인 gdb 로그 생김새는 하단과 같음.
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7c6b8b7 in __vfscanf_internal (s=0x7ffff7e038e0 <_IO_2_1_stdin_>,
format=0x404020 "%d", argptr=argptr@entry=0x7fffffffdc88,
mode_flags=mode_flags@entry=0) at ./stdio-common/vfscanf-internal.c:339
warning: 339 ./stdio-common/vfscanf-internal.c: No such file or directory