![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#41 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
If this MIPS thangy is worth a poot in a windstorm, then you can almost certainly AND an immediate value like 1. Please understand that any number can be expressed in any base. 1 (decimal), 0x01 (hex), 0001b, all those things contain the same value in your machine. The representation is for your brain. Those all look alike, but many don't. 10 (decimal), 0x0A (hex), and 00001010 (binary) ALL REPRESENT THE SAME EXACT PATTERN INSIDE YOUR MACHINE. This is something you must realize and come to terms with.
__________________
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 |
|
|
|
|
|
#42 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 333
Rep Power: 4
![]() |
.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
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 #set a
lw $t0,num2 #set b
xor $v1,$v0,$t0 # $v1 is c. compare $v0 and $t0 and store in $v1
move $s1, $zero #s1 is the counter set to 0
move $s2, $zero #set hamming to 0
li $s6,1 #set $s6 to 1
loop:
and $s4,$v1,$s6 #s4 is d and c with d store in $s4
beq $s4, 0,nohamming #jump to nohamming if $s4 is equal to 0
addi $s2, $s2, 1 #increment hamming
nohamming:
srl $v1, $v1, $s6 #shift c right by 1
addi $s1, $s1, 1 #i = i + 1 increment loop counter
ble $s1,32,loop #if loop counter <=32 go to loop
print:
la $a0,prompt_out #print prompt on terminal
li $v0,4 #prints a string on the terminal
syscall
move $a0, $s2 # syscall 1 prints an integer
li $v0, 1
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |