Implementation of bubble sort, utilizing Beta Assembly Language from MIT 6.004 Computational Structures.
.include "beta.uasm"
BR(STEP1) // start execution with Step 1
// the array to be sorted
A: LONG(10) LONG(56) LONG(27) LONG(69) LONG(73) LONG(99)
LONG(44) LONG(36) LONG(10) LONG(72) LONG(71) LONG(1)
ALEN = (. - A)/4 // determine number of elements in A
i = R29
swapped = R30
// Please enter your code for each of the steps below...
STEP1:
CMOVE(0, swapped)
STEP2:
CMOVE(0, i)
STEP3:
ADDC(i, 1, i)
CMPLTC(i, ALEN, R0)
BEQ(R0, STEP5, R31)
STEP4:
SHLC(i, 2, R1) // R1 holds shift for A[i]
SUBC(R1, 4, R2) // R2 holds shift for A[i - 1]
LD(R1, A, R3) // R3 holds value for A[i]
LD(R2, A, R4) // R4 holds value for A[i - 1]
CMPLE(R4, R3, R5) // R5 holds (A[i - 1] <= A[i])
BNE(R5, STEP3, R31)
ST(R4, A, R1)
ST(R3, A, R2)
CMOVE(1, swapped)
BEQ(R31, STEP3, R31) // return to STEP3 anyway
STEP5:
BNE(swapped, STEP1, R31)
// When step 5 is complete, execution continues with the
// checkoff code. You must include this code in order to
// receive credit for completing the problem.
.include "checkoff.uasm"
本文章使用limfx的vsocde插件快速发布