結果

問題 No.656 ゴルフ
ユーザー tonyu0tonyu0
提出日時 2020-05-20 14:01:28
言語 Assembler
(nasm 2.16.01)
結果
AC  
実行時間 0 ms / 2,000 ms
コード長 1,220 bytes
コンパイル時間 48 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 04:46:14
合計ジャッジ時間 521 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 0 ms
5,376 KB
testcase_04 AC 0 ms
5,376 KB
testcase_05 AC 0 ms
5,376 KB
testcase_06 AC 0 ms
5,376 KB
testcase_07 AC 0 ms
5,376 KB
testcase_08 AC 0 ms
5,376 KB
testcase_09 AC 0 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

section .bss
in_buf  resb  10
in_size resb  10
in_now resb 0
out_buf resb  2
out_size  resb  2

section .text
global _start
_start:
  call  read
  call  calc
  call  putint
  call  write
  call  exit

read:
  mov rax,  0
  mov rdi,  0
  mov rsi,  in_buf
  mov rdx,  10
  syscall
  ret

nextchar:
  mov rdi,  in_buf
  add rdi,  [in_now]
  mov al, [rdi]
  add word [in_now], 1
  ret

calc:
  xor rax,  rax
calc1:
  push  rax
  call  nextchar
  mov dil,  al
  pop rax
  cmp dil,  48
  ; 0 or 1~9 or 終端で別分岐
  jz  calc2
  jb  calc3
  movzx rcx,  dil
  sub rcx,  48
  add rax,  rcx
  jmp calc1
calc2:
  add rax,  10
  jmp calc1
calc3:
  mov rdi, rax
  ret


putchar:
  mov rax,  out_buf
  add rax,  [out_size]
  mov [rax],  dil
  mov rax,  [out_size]
  add rax,  1
  mov [out_size], rax
  ret
putint:
  mov rcx,  0
  mov rax,  rdi
putint_calc:
  cmp rax,  0
  je  putint_out
  xor rdx,  rdx
  mov rbx,  10
  div rbx
  push  rdx
  add rcx,  1
  jmp putint_calc
putint_out:
  pop rdi
  add rdi,  48
  push  rcx
  call  putchar
  pop rcx
  loop  putint_out
putint_ret:
  ret

write:
  mov rax,  1
  mov rdi,  1
  mov rsi,  out_buf
  mov rdx,  [out_size]
  syscall
  ret

exit:
  mov rax,  60
  xor rdi,  rdi
  syscall
0