x86_64 assembly (System V ABI, GNU assembler), as usual. Not really correct, since there will be an extra ' ' at the end which I was too lazy to remove, but it'll do.
' '
alphabetic_position.S
.global alphabetic_position .text alphabetic_position: #using these registers to avoid sprintf breaking them push %rbx push %rbp mov %rdi, %rbx mov %rdi, %r12 mov %rsi, %rbp xor %eax, %eax xor %edx, %edx loop: mov (%rbp), %dl cmp $65, %dl # 'A' jl skip cmp $91, %dl # 'Z' + 1 jl print cmp $97, %dl # 'a' jl skip cmp $123, %dl # 'z' + 1 ja skip printl: sub $32, %dl # 'a' -> 'A' print: sub $64, %dl # 'A' -> 1 push %rdx mov %rbx, %rdi mov $format, %rsi call sprintf add %rax, %rbx pop %rdx skip: inc %rbp cmp $0, %dl jne loop mov %r12, %rax pop %rbp pop %rbx ret .section .rodata format: .asciz "%d "
alphabetic_position.h:
char *alphabetic_position(char *dst, const char *src);
Edit: the function name now conforms to the specification, as well as with the "returns the string" requirement (by returning a copy of dst).
that's crazy
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
x86_64 assembly (System V ABI, GNU assembler), as usual. Not really correct, since there will be an extra
' '
at the end which I was too lazy to remove, but it'll do.alphabetic_position.S
alphabetic_position.h:
Edit: the function name now conforms to the specification, as well as with the "returns the string" requirement (by returning a copy of dst).
that's crazy