| Andrew Libby on 13 Sep 2017 16:42:46 -0700 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: [PLUG] Why Can't Programmers.. Program? |
Nice. I came up with a solution that I don't I saw, it's nothing
amazing, but it does only a single modulus per loop:
#!/usr/bin/env ruby
1.upto(100).each do |i|
puts(
case i % 15
when 0 then :FizzBuzz
when 3,6,9,12 then :Fizz
when 5,10 then :Buzz
else i
end
)
end
Andy
On 9/13/17 7:34 PM, Philip Rushik wrote:
> I find it hard to believe that there are actually programmers out there
> that can't solve that problem. I know non-programmers that could easily
> solve that problem (I asked a few). Anyways, for the sake of being
> annoying, I implemented this in just about the worst way possible, here
> yall go, enjoy:
>
> section .data
> fizz: db "fizz",10
> buzz: db "buzz",10
> num: db " "
> num1: db "0"
> num2: db "0"
> num3: db "0"
> db 10
> section .text
> global _start
>
> write_buzz:
> push rsi
> lea rsi, [buzz]
> call write
> pop rsi
> ret
>
> write_num:
> mov rax, rcx
> mov r10, 10
> xor rdx, rdx
> div r10
> cmp rdx, 5
> je write_buzz
> cmp rdx, 0
> je write_buzz
> add rdx, '0'
> mov [num3], dl
> xor rdx, rdx
> div r10
> add rdx, '0'
> add rax, '0'
> mov [num2], dl
> mov [num1], al
>
> lea rsi, [num]
> write:
> push rcx
> mov rax, 1
> mov rdi, 1
> mov rdx, 5
> syscall
> pop rcx
> ret
>
> _start:
> xor rcx, rcx
> _loop:
> inc rcx
> call write_num
> cmp rcx, 100
> jge _exit
> inc rcx
> call write_num
> inc rcx
> lea rsi, [fizz]
> call write
> mov rax, rcx
> xor rdx, rdx
> mov r10, 5
> div r10
> cmp rdx, 0
> jne _loop
> call write_buzz
> jmp _loop
>
> _exit:
> mov rax, 60
> syscall
>
>
>
> ___________________________________________________________________________
> Philadelphia Linux Users Group -- http://www.phillylinux.org
> Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
> General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
>
___________________________________________________________________________
Philadelphia Linux Users Group -- http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug