Computer Organization and Architecture
Final Project Q1 report
Bruno Diaz
In Thisprojectwe are requiredtowrite anencryptionprogram inMIPS.I designed itbyusing
three arrays array1, array2, and array3. The 1st
array iswhat isread fromthe stringthe user inputted,
the 2nd is the coded/decoded messageandthe third forstoringthe encryptionkeywhichisalsousedto
produce the 2nd
array. Unlike the othertwoarrays insteadof usinganindex i the thirdwill use the mask
h10010100 anda character readfromarray1 to code and decode charactersfromarray1 to array2. The
general software diagramisshowninfigure D-1.
The program firststart by askingforand thenreadinga Stringfromthe use whichis stored in
array1. It thenstepsthrougheveryindexof thisarray(equivalenttoabyte) to readeach character
determiningif itisa letterora number,todetermine if itisaletteror a numberwe lookat table t-1 and
we can see that a character from the stringisa numberif itisbetween48 and57, if it isthe character is
storedinarray2 unchanged. If the character isfoundto be a numberthenthe character needsto
coded/decodedwe dothisbyobservingthatrange 48-57 in decimal isalsothe range 30-39 in
hexadecimal, Iuse thistomy advantage byhavingthe addressof the encryptionkeybe h10010130 this
wayby usingthe mask 10010100 and applyinganOR to character readfrom array1 and determinedto
be a numberto getan addressinarray 3 as can be observedintable T-2
Thismeansthat the outputof the operationwill pointthe address of the memorylocationof the value it
needstobe turnedinto.For example: if ahex value 30 (equivalenttoascii 0) isread fromthe array it
getsORed withthe mask h10010100 whichgivesusthe value h10010130 whichif usedas an address
pointstoa hex value 34 (equivalenttoascii 4) whichthengetsstoredintoarray2.
These twooperationsthengivesusastoredstringinarray 2 that is ourcoded/decoded
message.A “/n” andthena null characterisaddedat the endto make a cleanerprintandterminate the
string.Afterthatis done array2 is thenprintedtoscreenandthe user askedif theywishtoterminate
the program. If a y or Y character equivalentto121 or 89 as seenintable T-1 is enteredthe program
loopsto the endwhere the programisended,otherwisethe programloopsbackto the beginningto
beginthe processall overagain.
The code forthe programand screenshotsare shownbelow
Code:
.data
start: .asciiz"Please inputphrase tocode/decode (29characterlimit)n"
ask: .asciiz"wouldyoulike toterminate the program? n"
new_line:.asciiz "n"
.text
.globl my_main
my_main:
li $s0,0x10010100 #load addressmask
li $s1,0x100100A0 #load the base adressof array1(inputstring)
li $s2,0x100100C0 #loadthe base adressof array2(outputstring)
li $s3,0x10010130 #load the base adressof array3(encryptioncode)
li $t0,0x35393634 #store the encryptioncode
sw $t0,0($s3)
li $t0,0x38313330
sw $t0,4($s3)
li $t0,0x00003237
sw $t0,8($s3)
addi $s4,$0,48 #lowerlimitfornumber
addi $s5,$0,57 #upperlimitfornumber
addi $s6,$0,89 #Y and
addi $s7,$0,121 #y
LOOP1:
li $v0,4 #print start
la $a0,start
syscall
li $v0, 8 # read string byusingsyscall
add $a0, $0,$s1 # loadfirstarray addressinto$a0
addi $a1, $0,29 #load the character limit
syscall
li $v0,4 #make newline
la $a0,new_line
syscall
addi $t2,$0,0 #offseti
LOOP2:
add $t3,$t2,$s1 #current adressinrespectto array1
add $t4,$t2,$s2 #current adressinrespectto array2
lb $t5,0($t3) #loadelementfromarray1[i]
beq$0,$t5,done #jumpto done if null character ispulledfromarray
slt$t6,$t5,$s4 #is it lessthan48?
bne $t6,$0,continue
slt$t6,$s5,$t5 #is it greaterthan57?
bne $t6,$0,continue
or $t7,$s0,$t5 #decrypt byreadingadressinrespectto the numberoredwiththe maskin array3
lb$t5,0($t7)
continue:
sb $t5,0($t4) #store intoarray 2[i]
addi $t2,$t2,1 #incrementi
j,LOOP2
done:
li $t5,0x5C6D0000 #store n and null chatacterintoendof array
addi $t4,$t4,1
sb $t5,0($t4)
li $v0,4 #printresult
or $a0,$s2,$0
syscall
li $v0,4 #make newline
la $a0,new_line
syscall
li $v0,4 #ask to terminate
la $a0,ask
syscall
li $v0,12 #read character
syscall
or $t8,$v0,$0
li $v0,4 #make newline
la $a0,new_line
syscall
beq$t8,$s6,finished#branchto finishif characterisY
beq$t8,$s7,finished#branchto finishif characterisy
j,LOOP1#branch to beginningloopif neither
finished:
li $v0,10 #exitprogram
syscall
Screenshots:
Screenshotfor codinga message
Screenshotfor decodingamessage
Conclusion:
I was able tocome upwitha MIPS designthatavoidedhavingtouse 10 differentbranchesto
decode numbersbyutilizingakeystoredinmemoryandusinga trick withthe addressandthe ASCII
valuesof numberspointtothe positioninthe keyforthe value itneededtobe turnedintoto. By doing
thisI alsohad the befitof beingable toeasilymodifythe type of encryptionshouldIneedto.Ialso
avoidedhavingtouse a for loopforthe iterationneededforthe characterread byusinga while loop
that keptreadingtill itfoundanull character essentiallyturningfor(i=0;i++;i<29) towhile(array[i]!=00)
thisgivesthe benefitof beingable tomodifythe size of the inputtedstringshouldone needto.Soin
conclusionIcame up witha compact design(77 lineslong) foraMIPS encryptedthatiseasily
modifiable.

compuorg final

  • 1.
    Computer Organization andArchitecture Final Project Q1 report Bruno Diaz In Thisprojectwe are requiredtowrite anencryptionprogram inMIPS.I designed itbyusing three arrays array1, array2, and array3. The 1st array iswhat isread fromthe stringthe user inputted, the 2nd is the coded/decoded messageandthe third forstoringthe encryptionkeywhichisalsousedto produce the 2nd array. Unlike the othertwoarrays insteadof usinganindex i the thirdwill use the mask h10010100 anda character readfromarray1 to code and decode charactersfromarray1 to array2. The general software diagramisshowninfigure D-1. The program firststart by askingforand thenreadinga Stringfromthe use whichis stored in array1. It thenstepsthrougheveryindexof thisarray(equivalenttoabyte) to readeach character determiningif itisa letterora number,todetermine if itisaletteror a numberwe lookat table t-1 and we can see that a character from the stringisa numberif itisbetween48 and57, if it isthe character is storedinarray2 unchanged. If the character isfoundto be a numberthenthe character needsto coded/decodedwe dothisbyobservingthatrange 48-57 in decimal isalsothe range 30-39 in hexadecimal, Iuse thistomy advantage byhavingthe addressof the encryptionkeybe h10010130 this wayby usingthe mask 10010100 and applyinganOR to character readfrom array1 and determinedto be a numberto getan addressinarray 3 as can be observedintable T-2
  • 2.
    Thismeansthat the outputofthe operationwill pointthe address of the memorylocationof the value it needstobe turnedinto.For example: if ahex value 30 (equivalenttoascii 0) isread fromthe array it getsORed withthe mask h10010100 whichgivesusthe value h10010130 whichif usedas an address pointstoa hex value 34 (equivalenttoascii 4) whichthengetsstoredintoarray2. These twooperationsthengivesusastoredstringinarray 2 that is ourcoded/decoded message.A “/n” andthena null characterisaddedat the endto make a cleanerprintandterminate the string.Afterthatis done array2 is thenprintedtoscreenandthe user askedif theywishtoterminate the program. If a y or Y character equivalentto121 or 89 as seenintable T-1 is enteredthe program loopsto the endwhere the programisended,otherwisethe programloopsbackto the beginningto beginthe processall overagain. The code forthe programand screenshotsare shownbelow Code: .data start: .asciiz"Please inputphrase tocode/decode (29characterlimit)n" ask: .asciiz"wouldyoulike toterminate the program? n" new_line:.asciiz "n" .text .globl my_main my_main: li $s0,0x10010100 #load addressmask li $s1,0x100100A0 #load the base adressof array1(inputstring) li $s2,0x100100C0 #loadthe base adressof array2(outputstring)
  • 3.
    li $s3,0x10010130 #loadthe base adressof array3(encryptioncode) li $t0,0x35393634 #store the encryptioncode sw $t0,0($s3) li $t0,0x38313330 sw $t0,4($s3) li $t0,0x00003237 sw $t0,8($s3) addi $s4,$0,48 #lowerlimitfornumber addi $s5,$0,57 #upperlimitfornumber addi $s6,$0,89 #Y and addi $s7,$0,121 #y LOOP1: li $v0,4 #print start la $a0,start syscall li $v0, 8 # read string byusingsyscall add $a0, $0,$s1 # loadfirstarray addressinto$a0 addi $a1, $0,29 #load the character limit syscall li $v0,4 #make newline la $a0,new_line syscall addi $t2,$0,0 #offseti LOOP2: add $t3,$t2,$s1 #current adressinrespectto array1 add $t4,$t2,$s2 #current adressinrespectto array2 lb $t5,0($t3) #loadelementfromarray1[i] beq$0,$t5,done #jumpto done if null character ispulledfromarray slt$t6,$t5,$s4 #is it lessthan48? bne $t6,$0,continue slt$t6,$s5,$t5 #is it greaterthan57? bne $t6,$0,continue or $t7,$s0,$t5 #decrypt byreadingadressinrespectto the numberoredwiththe maskin array3 lb$t5,0($t7) continue: sb $t5,0($t4) #store intoarray 2[i] addi $t2,$t2,1 #incrementi j,LOOP2 done: li $t5,0x5C6D0000 #store n and null chatacterintoendof array addi $t4,$t4,1 sb $t5,0($t4) li $v0,4 #printresult or $a0,$s2,$0
  • 4.
    syscall li $v0,4 #makenewline la $a0,new_line syscall li $v0,4 #ask to terminate la $a0,ask syscall li $v0,12 #read character syscall or $t8,$v0,$0 li $v0,4 #make newline la $a0,new_line syscall beq$t8,$s6,finished#branchto finishif characterisY beq$t8,$s7,finished#branchto finishif characterisy j,LOOP1#branch to beginningloopif neither finished: li $v0,10 #exitprogram syscall Screenshots:
  • 5.
  • 6.
    Screenshotfor decodingamessage Conclusion: I wasable tocome upwitha MIPS designthatavoidedhavingtouse 10 differentbranchesto decode numbersbyutilizingakeystoredinmemoryandusinga trick withthe addressandthe ASCII valuesof numberspointtothe positioninthe keyforthe value itneededtobe turnedintoto. By doing thisI alsohad the befitof beingable toeasilymodifythe type of encryptionshouldIneedto.Ialso avoidedhavingtouse a for loopforthe iterationneededforthe characterread byusinga while loop that keptreadingtill itfoundanull character essentiallyturningfor(i=0;i++;i<29) towhile(array[i]!=00) thisgivesthe benefitof beingable tomodifythe size of the inputtedstringshouldone needto.Soin conclusionIcame up witha compact design(77 lineslong) foraMIPS encryptedthatiseasily modifiable.