Frage

Zusammenfassung Ihr Ziel für dieses Projekt ist die Implementierung der Software-Emulation der schwimmenden Punktzahlen für 32-Bit-Schwimmpunktzahlen in MIPs.

Eingabe/Ausgabe Ihr Programm fordert den Benutzer für zwei schwimmende Punktnummern auf.Es wird dann berechnet und die Summe angezeigt.Hier ist ein Beispiel für I/O aus vier Läufen (Sie müssen nur einmal pro Ausführungsausführung fordern):

Geben Sie einen Gleitkommawert ein:1 Geben Sie einen Schwimmpunktwert ein:1 2.000000000000000000

Geben Sie einen Gleitkommawert ein:2.2 Geben Sie einen Schwimmpunktwert ein:1.4 3.599999904632568400

Probleme zur Lösung hier sind einige Probleme: Wie gehen Sie mit negativen Werten um? Wie funktioniert Ihr Normalisierungsalgorithmus? Was ist der einfachste Weg, auf Bitfelder innerhalb eines Wortes zuzugreifen?

*Sie dürfen für dieses Projekt keine Gleitkommaanweisungen verwenden!!*

Ich habe das Gleiche mit Ganzzahlen gemacht, brauche aber Hilfe bei Gleitkommazahlen, ohne sie zu verwenden!.Data ST1:.asciiz " nin Binary: n" ST2:.Asciiz " nenter 1st Integer:" ST3:.asciiz " nenter 2. Ganzzahl:" ST4:.asciiz " Ihre Antwort ist:"ST5:.asciiz " n ---------------------------- n" ST6:.asciiz „ “

.text

main: 

Fordern Sie den Benutzer auf, die erste Ganzzahl einzugeben

la $a0,st2 # Put the address of the string in $a0   
li $v0, 4
syscall
li $v0, 5  # Code for input integer
syscall
move $s1, $v0 #storing first integer in s1

Fordern Sie den Benutzer auf, die erste Ganzzahl einzugeben

la $a0,st3 # Put the address of the string in $a0
 li $v0, 4
syscall
li $v0, 5  # Code for input integer
syscall
move $s2, $v0 #storing second integer in s2

Ganzzahlen hinzufügen

add $s0,$s2,$s1 #add and store in t3

Ergebnis anzeigen

la $a0,st4 #text to display 
li $v0,4
syscall  
li $v0,1     #for printing int
 move $a0,$s0 # move s0 to a0 to print s0
syscall
la $a0,st1
li $v0,4
syscall

Wechseln Sie in temporäre Register

move $t3,$s0   
move $t2,$s2
move $t1,$s1

Zähler für die erste Zahl, die binär gedruckt werden soll

li $s5,32       # set up counter
loop1: 
    rol  $t1,$t1,1   #roll the bit left by on bit high to low
    and  $t0,$t1,1   #mask off low bit
    add  $t0,$t0,48  #combine t0 with 48 to form 1 or 0
    move $a0,$t0     #output ascii character
    li   $v0,11
    syscall
    li $t5,1
    sub $s5,$s5,$t5  #decrement counter
    bne $s5,$zero,loop1 #keep loop if not zero

Drucken Sie eine Zeile

la $a0,st6  
li $v0,4
syscall  

Zähler für die zweite Zahl im Binärformat

li $s5,32     
loop2: 
    rol  $t2,$t2,1   #roll the bit left by on bit high to low
    and  $t0,$t2,1   #mask off low bit
    add  $t0,$t0,48  #combine t0 with 48 to form 1 or 0
    move $a0,$t0     #output ascii character
    li   $v0,11
    syscall
    li $t5,1
    sub $s5,$s5,$t5  #decrement counter
    bne $s5,$zero,loop2 #keep loop if not zero

Drucken Sie eine gepunktete Linie

la $a0,st5 #line 
li $v0,4
syscall  

Zähler für Ergebnis in Binärform

li $s5,32       
loop: 
    rol  $t3,$t3,1   #roll the bit left by on bit high to low
    and  $t0,$t3,1   #mask off low bit
    add  $t0,$t0,48  #combine t0 with 48 to form 1 or 0
    move $a0,$t0     #output ascii character
    li   $v0,11
    syscall
    li $t5,1
    sub $s5,$s5,$t5  #decrement counter
    bne $s5,$zero,loop #keep loop if not zero

Schließe das Programm

li $v0,10 #close the program
syscall

.end main

War es hilfreich?

Lösung

1- Verwenden Sie IEEE 754, um Ihre schwimmenden Punktnummern 2- Fügen Sie die Exponenten hinzu und addieren Sie dann die Signalanden und prüfen Sie, ob Sie den Exponent 3-Deal mit negativen Vorzeichen erhöhen müssen (2-Komplement, einzelnes Bit Das erste Repräsentationszeichen)

Dies ist ein ziemlich einfaches Problem und ich stimme den obigen Kommentaren zu. Ich dachte nur, Sie könnten ein paar gute Tipps verwenden. Viel Glück!

Andere Tipps

.data
st1: .asciiz "\nIn binary:\n"
st2: .asciiz "\nEnter 1st Integer:"
st3: .asciiz "\nEnter 2nd Integer:"
st4: .asciiz "\nYour answer is: "
st5: .asciiz "\n--------------------------------\n"
st6: .asciiz "\n"

.text

main: 

Fordern Sie den Benutzer auf, die erste Ganzzahl einzugeben

la $a0,st2 # Put the address of the string in $a0   
li $v0, 4
syscall
li $v0, 5  # Code for input integer
syscall
move $s1, $v0 #storing first integer in s1

Fordern Sie den Benutzer auf, die erste Ganzzahl einzugeben

la $a0,st3 # Put the address of the string in $a0
 li $v0, 4
syscall
li $v0, 5  # Code for input integer
syscall
move $s2, $v0 #storing second integer in s2

Ganzzahlen hinzufügen

add $s0,$s2,$s1 #add and store in t3

Ergebnis anzeigen

la $a0,st4 #text to display 
li $v0,4
syscall  
li $v0,1     #for printing int
 move $a0,$s0 # move s0 to a0 to print s0
syscall
la $a0,st1
li $v0,4
syscall

Wechseln Sie in temporäre Register

move $t3,$s0   
move $t2,$s2
move $t1,$s1

Zähler für die erste Zahl, die binär gedruckt werden soll

li $s5,32       # set up counter
loop1: 
    rol  $t1,$t1,1   #roll the bit left by on bit high to low
    and  $t0,$t1,1   #mask off low bit
    add  $t0,$t0,48  #combine t0 with 48 to form 1 or 0
    move $a0,$t0     #output ascii character
    li   $v0,11
    syscall
    li $t5,1
    sub $s5,$s5,$t5  #decrement counter
    bne $s5,$zero,loop1 #keep loop if not zero

Drucken Sie eine Zeile

la $a0,st6  
li $v0,4
syscall  

Zähler für die zweite Zahl im Binärformat

li $s5,32     
loop2: 
    rol  $t2,$t2,1   #roll the bit left by on bit high to low
    and  $t0,$t2,1   #mask off low bit
    add  $t0,$t0,48  #combine t0 with 48 to form 1 or 0
    move $a0,$t0     #output ascii character
    li   $v0,11
    syscall
    li $t5,1
    sub $s5,$s5,$t5  #decrement counter
    bne $s5,$zero,loop2 #keep loop if not zero

Drucken Sie eine gepunktete Linie

la $a0,st5 #line 
li $v0,4
syscall  

Zähler für Ergebnis in Binärform

li $s5,32       
loop: 
    rol  $t3,$t3,1   #roll the bit left by on bit high to low
    and  $t0,$t3,1   #mask off low bit
    add  $t0,$t0,48  #combine t0 with 48 to form 1 or 0
    move $a0,$t0     #output ascii character
    li   $v0,11
    syscall
    li $t5,1
    sub $s5,$s5,$t5  #decrement counter
    bne $s5,$zero,loop #keep loop if not zero

Schließe das Programm

li $v0,10 #close the program
syscall

.end main

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top