Guard's Tumblr

Woxat of All Trades, Master of None

2 notes &

Pointless Assembly Code

Writing some Assembly code because fuck. (To help a friend out with their programming course.) Actually I wrote this a long time back and am only posting it now in case his professor googles the submitted code and he doesn’t change it and then gets in trouble.

		.data
integer1:		.byte	0
integer2:		.byte	0
print_int:		.byte	1
read_int:		.byte	5
range:			.byte	20
print_string:	.byte	4
string:			.asciiz	" is the result\n"

		.text
main:		lw $v0,read_int		# service call
			syscall				# read an integer

			bltz $v0,main		# if less then zero, goto main
			lw $s0,range		# load range value
			sub $t0,$s0,$v0		# subtract twenty to check if above 20
			bgtz $t0,main		# if above zero, goto main

			sb $v0, integer1	# store in integer1

int2:		lw $v0,read_int		# service call
			syscall				# read an integer

			bltz $v0,int2		# if <0, jump to int2
			sub $t0,$s0,$v0		# sub 20 to check range
			bgtz $t0,int2		# if >0, jump to int2

			sb $v0, integer2	# store in integer2
#(integer1+integer2)*8
			lw $v0,integer1		# load integers
			lw $v1,integer2
			add $a0,$v0,$v1		# add them

			add $a0,$a0,$a0		# add this to itself (x2)
			add $a0,$a0,$a0		# add to self again  (x4)
			add $a0,$a0,$a0		# add AGAIN          (x8)
#print result
			lw $v0,print_int	# service call (result is already in $a0)
			syscall				# print result
			lw $v0,print_string	# service call
			la $a0,string		# load address of string
			syscall				# print message string

			j main				# repeat all

All that fucking does is asks for two integers, checks if they are in the range of 0-20 (asking again if they aren’t), then adds them together and multiplies that by 8, then does it all again. I wasn’t allowed to use li (load immediate) or mul (multiply) or subi (subtract immediate), all of which would have made this a bit easier.

This is using the MIPS instruction set btw.

Filed under assembly programming uggghhhhhh why I remembered why I quit writing assembly

0 notes &

kylumgaming asked: Why isn't your youtube link on this blog? You should really really do that because I did it and it looks nice and flows and stuff do it now NOW NOW NOW NOW NO STOP THAT NO DON'T DO THAT DO IT NOW DO IT

A. I made it before the YouTube…no wait…I might not have, but I made it before the YouTube became a real thing.

B. I am dumb.

C. I don’t know how. I’ll probably find out in the next two minutes, or get distracted by something shiny.