CSES - Datatähti 2022 alku - Results
Submission details
Task:Karkit (Candy)
Sender:EmilCoder
Submission time:2021-10-13 18:31:36
Language:Assembly
Status:COMPILE ERROR

Compiler report

output/code.o: In function `_start.loop1':
input/code.asm:(.code+0x25): undefined reference to `gets_s'
input/code.asm:(.code+0x34): undefined reference to `atoi'
input/code.asm:(.code+0x78): undefined reference to `_itoa_s'
output/code.o: In function `_start.loop2':
input/code.asm:(.code+0x98): undefined reference to `_putch'
output/code.o: In function `_start.loop2_end':
input/code.asm:(.code+0xa7): undefined reference to `exit'

Code

; Imports:
extern exit
extern _putch
extern gets_s
extern atoi
extern _itoa_s

; Exports:
global _start

section .code code
_start:
; Align stack:
    push rax
; Get numbers:
mov ecx, 3
mov rdi, value1
.loop1:
    push rcx
    sub rsp, 40
    mov rcx, char_buffer ; *buffer
    mov rdx, 12 ; sizeInCharacters
    call gets_s
    mov rcx, char_buffer ; *buffer
    call atoi
    stosd
    add rsp, 40
    pop rcx
    loop .loop1
; Calculate the value:
    ; Get the smaller candy price:
        mov eax, [rel value3]
        mov ebx, [rel value2]
        cmp ebx, eax
        cmovg ebx, eax ; Assumption: All x64 CPUs support CMOV.
    ; Divide the amount of money by the candy price:
        xor edx, edx
        mov eax, [rel value1]
        div ebx
; Convert EDX to the value to output:
    sub rsp, 32
    mov ecx, eax ; value
    mov rdx, char_buffer ; buffer
    mov r8d, 12 ; size
    mov r9d, 10 ; radix
    call _itoa_s
    add rsp, 32
; Output the number:
    ; Prepare index:
        mov rsi, char_buffer
    ; Do it:
    .loop2:
        xor eax, eax
        lodsb
        test eax, eax
        jz .loop2_end
        sub rsp, 32
        mov ecx, eax ; c
        call _putch
        add rsp, 32
        jmp .loop2
    .loop2_end:
; Exit the process:
    sub rsp, 32
    call exit
; Static allocations:
section .bss bss
value1: resd 1
value2: resd 1
value3: resd 1
char_buffer: resb 12