Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 30th, 2006, 10:53 PM   #11
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
There are representations of values and true binary values. The ASCII code is a representation. To get the actual value, see my first post. If the instruction gives you the number already reduced to its true binary value, then all you have to do is work with it. Please read the posts and think about them. The effer is binary. The print converts it to ink on paper or glowing dots on some other output media. It's still binary in your machine. Ones and zeros. In (for typical integers) weighted positions.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 30th, 2006, 10:56 PM   #12
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 327
Rep Power: 4 cwl157 is on a distinguished road
when i enter 1 for an input i get 0x34020005 does that mean anything?
cwl157 is offline   Reply With Quote
Old Nov 30th, 2006, 10:59 PM   #13
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 327
Rep Power: 4 cwl157 is on a distinguished road
so when i print it to the screen it prints 4 cause thats what people understand? So then in the machine its binary. So then if i work with the number no matter what it prints to the screen when i'm working with it in xor gates and all that it should be the binary equivilent even though there is no way for me to see it to make sure?
cwl157 is offline   Reply With Quote
Old Nov 30th, 2006, 11:12 PM   #14
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 816
Rep Power: 4 The Dark is on a distinguished road
Quote:
Originally Posted by cwl157 View Post
when i enter 1 for an input i get 0x34020005 does that mean anything?
Get 0x34020005 where? How do you know you got that value?
The Dark is offline   Reply With Quote
Old Nov 30th, 2006, 11:13 PM   #15
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 816
Rep Power: 4 The Dark is on a distinguished road
Quote:
Originally Posted by cwl157 View Post
so when i print it to the screen it prints 4 cause thats what people understand? So then in the machine its binary. So then if i work with the number no matter what it prints to the screen when i'm working with it in xor gates and all that it should be the binary equivilent even though there is no way for me to see it to make sure?
Yes its binary internally - there may be a way to print it out as binary, but I don't know how.
The Dark is offline   Reply With Quote
Old Nov 30th, 2006, 11:41 PM   #16
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 327
Rep Power: 4 cwl157 is on a distinguished road
i went step by step in the simulator im using called pcspim and when i entered the value 1 thats what it gave me. So if its binary internally then i should be able to do all the xor stuff as entered even if the user is required to enter a decimal number?
cwl157 is offline   Reply With Quote
Old Dec 1st, 2006, 7:08 AM   #17
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
When a user enters a decimal number it is typically presented to the system as a chain of decimal digits expressed in some binary code (ASCII, EBCDIC, unicode, etc.). If your machine doesn't automatically handle the decoding (most don't), then it's your responsibility. Typically, this is done by reducing each digit to its unweighted, actual value and then recombining it using the appropriate decimal weights. I'm compelled to say that you seem to be messing around under the hood without having been taught about nuts, bolts, wrenches, and carburetors.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Dec 4th, 2006, 3:20 PM   #18
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 327
Rep Power: 4 cwl157 is on a distinguished road
ok so i think i got i incrementing for the loop. Now how do I know when all the bits have been shifted and i can exit the loop? Also, i don't know how to print things i wish i could so i could see whats actually happening.
.text

main:
	la $a0,prompt_in      #print prompt on terminal
	li $v0,4              #prints a string on the terminal
	syscall

	li $v0,5	      #reads in an integer
	syscall
	sw $v0,num1
	#move $a0,$v0
	#li $v0,1	      #prints integer
	#syscall

	la $a0,prompt_ina      #print prompt on terminal
	li $v0,4               #prints a string on the terminal
	syscall

        li $v0,5	       #reads in an integer
	syscall
	sw $v0,num2

	lw $v0,num1
	lw $t0,num2
	move $s1, $zero		#s1 is the counter
loop:
	addi $s1, $s1, 1	#i = i + 1
	
	xor $v1,$v0,$t0
	#bit shift one bit
	#compare those
	#keep going till there are no more bits
	#do the same thing but have the comparison be an and
	#then increment a counter for each 1 returned.
	#return counter as the hamming distance
	


	li $v0,10              #exit program
	syscall



.data
prompt_in:    .asciiz "Enter first integer: "            # first integer
prompt_ina:    .asciiz "Enter second integer: "          #second integer
prompt_out:   .asciiz "The hamming distance is "
num1: .word 0
num2: .word 0
cwl157 is offline   Reply With Quote
Old Dec 4th, 2006, 3:33 PM   #19
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You shift in a loop until you have shifted as many times as there are bits in the register or registers in question. Again, I can't give you specifics, such as how to output a value; I don't know the MIPS. Still, these operations should be a part of your documentation. Almost bound to be a syscall for it. At least, you have those. When you start with a raw micro and no library stuff, you have to write it all.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Dec 4th, 2006, 7:16 PM   #20
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 327
Rep Power: 4 cwl157 is on a distinguished road
alright now its saying that all the stuff in the .data section is undefined.
.text

main:
	la $a0,prompt_in      #print prompt on terminal
	li $v0,4              #prints a string on the terminal
	syscall

	li $v0,5	      #reads in an integer
	syscall
	sw $v0,num1
	#move $a0,$v0
	#li $v0,1	      #prints integer
	#syscall

	la $a0,prompt_ina      #print prompt on terminal
	li $v0,4               #prints a string on the terminal
	syscall

        li $v0,5	       #reads in an integer
	syscall
	sw $v0,num2

	lw $v0,num1
	lw $t0,num2
	move $s1, $zero		#s1 is the counter
loop:	
	addi $s1, $s1, 1	#i = i + 1
	
	#xor $v1,$v0,$t0	#compare $v0 and $t0 and store in $v1
	lw $v2, num3[i]		#load the contents of num3[i] into $v2
	move $v2,$v1		#move the conntents of $v1 into $v2
	sw $v2, num3[i]		#save the contents $v2 into num3[i]
	#bit shift one bit
	#repeat loop
loop:
	#load array
	#increment counter for each i
	#return counter as hamming distance

        la $a0,prompt_out      #print prompt on terminal
	li $v0,4              #prints a string on the terminal
	syscall



	li $v0,10              #exit program
	syscall



.data
prompt_in:    .asciiz "Enter first integer: "            # first integer
prompt_ina:    .asciiz "Enter second integer: "          #second integer
prompt_out:   .asciiz "The hamming distance is "
num1: .word 0
num2: .word 0
#num3: .word 0,0,0					#array to hold 1's

Also any idea of what to initialize that array to. It's gonna have to be big enough to hold the largest of the numbers entered because it has to have enough spaces to hold one bit for each bit that the numbers are.
cwl157 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Assembly Language for Intel-Based Computers melbolt Book Reviews 0 Aug 15th, 2006 12:04 AM
Language display in program Prm753 C++ 3 May 30th, 2006 5:45 PM
More languages? UnKnown X Coder's Corner Lounge 27 Dec 18th, 2005 3:06 PM
Does assembly language vary per machine? Xero Assembly 9 Jan 17th, 2005 11:34 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:17 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC