Вы находитесь на странице: 1из 3

.

ORIG x3000 LD R3 INCRE ;First load number of times looping the bubblesort overall into R3 LD R4 INCRO ;First load number of times incrementing the numbers into R4 Brnzp PSEUDO START ADD R3 R3 -1 ;This is a decrementation for number of times to loop bubblesort Brz RANGE ;If it reaches 0, it will go straight to RANGE to store median and range to respective memory locations PSEUDO LD R5 ORIGIN ;Because at the beginning, the x3100 isn't in store1, we need to put it there for rst time around by loading it rst into a register. LD R6 NEXT ;Because at the beginning, the x3101 isn't in store2, we need to put it there for rst time around by loading it rst into a register. ST R5 store1 ;Now after it's in register, store it into store1 ST R6 store2 ;Now after it's in register, store it into store2 LDI R0 store1 ;Now you have to load the value in the address INSIDE store1 into R0 LDI R1 store2 ;Now you have to load the value in the address INSIDE store2 into R1 Brnzp Subtract ;A non-conditional jump straight to subtract

Pointer ADD R4 R4 -1 ;This is the decrementation for the number of times we're incrementing the numbers. Brz START ;If it reaches 0, it goes back to ORIGIN for another round of bubblesorting ADD R5 R5 1 ;I increment the pointer by 1 ADD R6 R6 1 ;I increment the pointer by 1 ST R5 store1 ;I store it in a BLKW ST R6 store2 ;I store it in a BLKW

LDI R0 store1 ; Then I LDI it back into R5, which is grabbing the value AT the memory location located inside store1 LDI R1 store2 ; Then I LDI it back into R6, which is grabbing the value AT the memory location located inside store2

Subtract NOT R1 R1 ;Make R1 negative by ipping it ADD R1 R1 1 ;Add 1 because it's 2's complement ADD R2 R0 R1 ;You add but really it's subtracting to nd out if it's negative or not.

Brn Pointer

ST R1 store3 ;This is the SWAP part. I store R1 into store3 because if I don't, it will be lost after I move R0 into R1 because of overwriting. ADD R1 R0 0 ;I move R0 into R1 LD R0 store3 ;I move the value from store3, which is R1, into R0, completing the SWAP. STI R0 store1 ;Then I store R0 into the memory location located INSIDE store1 STI R1 store2 ;Then I store R1 into the memory location located INSIDE store2

Brnzp Pointer

RANGE LDI R6 LOW ;Load the value at memory location x3100 into R6 LDI R7 HIGH ;Load the value at memory location at x310E into R7 NOT R6 R6 ;I'm not-ing it to ip it rst ADD R6 R6 1;Add one because its 2's complement ADD R5 R6 R7; In order to nd out the range through subtraction

STI R5 ST1;After getting range, I store it to x310F LDI R5 MED ;I load the value at location x107 into R5 STI R5 ST2 ;I then store the median into x3110 from R0

HALT store1 .BLKW 1 store2 .BLKW 1 store3 .BLKW 1 INCRE .FILL x000E INCRO .FILL x000D ORIGIN .FILL x3100 NEXT .FILL x3101 HIGH .FILL x310E MED .FILL x3107 LOW .FILL x3100 ST1 .FILL x310F ST2 .FILL x3110 .END