katster: (Default)
[personal profile] katster

Not that you'd understand this, or anything...but here's a program in MIPS assembly to take a keyboard decimal number and turn it into a hexadecimal number. ph33r.

.data
prompt: .asciiz "Give me a number\n"
buffer: .asciiz "0x       "
.globl main
.text

main:
	li $v0,4
	la $a0,prompt
	syscall

	li $v0,5
	syscall

	move $a0,$v0

	la $a1, buffer
	addi $a1,$a1, 10
	li $s1,57
	li $t0,8

hexloop: 
	andi $t1, $a0, 15
	addi $t1, $t1, 0x30
	ble $t1,$s1, here
	addi $t1,$t1,7
	
here:
	sb $t1, 0($a1)
	addi $a1,$a1,-1
	srl $a0,$a0,4
	addi $t0,$t0,-1
	bgtz $t0, hexloop

li $v0,4
la $a0,buffer
syscall

li $v0,10
syscall

Now...to incorporate it into my first programming assignment...

You are my personal goddess.

Date: 2001-10-02 09:00 pm (UTC)
From: [identity profile] loopychew.livejournal.com
Take me! Make me your disciple! I don't get a word (no pun intended) of MIPS assembly, and I need to for my Principles of Computer Organization class!

...well, okay, I get SOME of it, but not nearly everything you've got covered here. What're 'la (I assume it means something like Load-Add),' 'ble,' and 'bgtz?' We haven't gotten to those yet, and now you're making me curious. :P

Re: You are my personal goddess.

Date: 2001-10-03 02:30 am (UTC)
From: [identity profile] shadur.livejournal.com
At a guess, "Branch if larger or equal" and "Branch if greater than zero"
Not only do those match the abbreviations, they're the only instruction types that make sense in the context.

Re: You are my personal goddess.

Date: 2001-10-03 06:07 am (UTC)
From: [identity profile] katster.livejournal.com
ble == branch if less than or equal
bgtz == branch if greater than zero.

Close, Shad. :)

la is "load address", it's how something like a text string is loaded into memory. And the "0x " is definitely a text string. I'm adding more to that string, and then outputting.

-kat

muah ha ha ha.

Date: 2001-10-03 08:27 am (UTC)
From: [identity profile] phenyx.livejournal.com
> [ music | Leahy - Moment ]


First Keelaghan, now Leahy.

*scribbles on a clipboard*

the Canadianization is proceeding ahead of schedule. Excellent.

Re: muah ha ha ha.

Date: 2001-10-03 12:12 pm (UTC)
From: [identity profile] katster.livejournal.com
if I start spelling check with a q, I want you to kill me immediately.

-kat

same version in C++

Date: 2001-10-03 11:17 pm (UTC)
From: [identity profile] peruano.livejournal.com
#include "iostream.h"
void main() { int x; cin >>x; cout << hex << x; }

I'm pretty sure you know this :)
So pardon me, I was just bored!
PS: I just put the " because the 'less than' symbol would get mistaken by an HTMl tag

Note

My main blog is kept at retstak.org. I mirror posts to this Dreamwidth account, so feel free to read and comment either here or there.

November 2020

S M T W T F S
1234 567
891011121314
15161718192021
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 15th, 2026 02:07 pm
Powered by Dreamwidth Studios