Solving a Quora Programming Homework Question in ARM Assembly
Learn one dev's approach to building an ARM Assembly with Raspberry Pi.
Join the DZone community and get the full member experience.Join For Free
It makes me sad when students ask the online communities: ‘please write me a program that does the following...' Not only is this flat out dishonest to ask someone else to do your homework for you, the opportunity for learning is in the process of solving the problem and writing the code yourself. If someone else writes the code, you’ve missed that opportunity. There’s little to be learned if someone else does the hard work and gives you the final result.
Most communities police these types of questions pretty well. Reviewers on StackOverflow, for example, are quick to respond to these types of questions to help developers restructure a generic request for help into a specific question about a specific problem that the developer need help with. The guides that are usually referred to on suggestions to restructure these questions are actually very good advice and reminders for us all on how to ask good questions:
On other community sites, the community response goes in a different direction. This question for help on how to write a program was responded to be some of the funniest and bizarre approaches to solve the askers' problem in all sorts of obscure language from Brainfuck to Whitespace and plenty of other weirdness in between.
Not to be left out but a little later to the party, I realized I hadn’t done any ARM assembly for a while, so here’s my solution in ARM Assembly that I developed on my Raspberry Pi:
.global main main: MOV R4, #3 @ init outer line counter =3 _outerloop: MOV R3, R4 @ init word loop counter with current value of outer counter _wordloop: MOV R7, #4 @ syscall 4: output to stdout MOV R0, #1 @ stdout MOV R2, #6 @ length of string LDR R1, =output SWI 0 SUB R3, R3, #1 @ decrement word loop counter CMP R3, #0 BNE _wordloop @print newline MOV R7, #4 @ syscall 4: output to stdout MOV R0, #1 @ stdout MOV R2, #1 @ length of string LDR R1, =eol SWI 0 SUB R4, R4, #1 @ decrement outer counter CMP R4, #0 BNE _outerloop _exit: MOV R1, #0 MOV R7, #1 SWI 0 .data output: .asciz "Smile!" eol: .asciz "\n"
Published at DZone with permission of Kevin Hooke, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.