1
votes

I'm currently working on a project that requires me to write a bubble sort algorithm in Harvard Machine 16 Bit Assembly Code. I tried searching for it online, however most assembly code snippets use the CMP and MOV operators.

I have the following instruction available: ADD, SUB, AND, Copy, ADDI, SUBI, ANDI, LOADI, BZ, BEQ, BRA, SW, LW.

Could anyone please give me a nudge in the proper direction?

Thanks in advance,

1
Why don't you use insertion sort instead? It is equally easy to understand and implement, but it is faster in most cases, and never slower. The optimization of chained swaps (which reduces the number of assignments to nearly 2 per swap instead of 3) is pretty natural in insertion sort, but quite difficult in bubble sort. - comocomocomocomo
Hi, the assignment given to me specifies that I have to use bubble-sort (This would not have been my choice of sorting-algorithm) - user2051667

1 Answers

2
votes

You can always implement an equivalent of CMP using SUB (or even ADD if SUB isn't available).

MOV can always be constructed out of a load and a store. You could also simulate it using a load and ADD to a zero-initialized register or memory location.

Don't search. Write the algorithm in pseudo-code and see how you can construct each step with the instructions you've got.