Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// GUTIERREZ JUAN LUCAS 2023
- /// MARIE test bubble sort algorithm
- ORG 000
- Jump START
- ARRAY, DEC 1 // SIZE
- DEC 1 // FIRST ELEMENT
- START, Load ARRAY
- Store SIZE // load SIZE with the size of the array
- FORj, Load START_ADDR
- Store CURRENT
- Load ZERO // clear INDEX_I and IS_VAL
- Store INDEX_I
- Store IS_SWAP
- Load INDEX_J // INDEX_J++
- Add ONE
- Store INDEX_J
- Subt SIZE
- Skipcond 400 // if INDEX_J == SIZE then jump END else jump FORi
- Jump FORi
- Jump END
- FORi, Load INDEX_I // INDEX_I++
- Add ONE
- Store INDEX_I
- Add INDEX_J // INDEX_I + INDEX_J
- Subt SIZE // if INDEX_I + INDEX_J == SIZE then jump CHECK_PRE_END else jump COMPARE current and next
- Skipcond 400
- Jump COMPARE
- Jump CHECK_PRE_END
- DO, Load CURRENT // CURRENT++
- Add ONE
- Store CURRENT
- Jump FORi
- COMPARE, Load CURRENT
- Add ONE
- Store NEXT
- LoadI NEXT
- Store NEXT_VAL
- LoadI CURRENT
- Subt NEXT_VAL
- Skipcond 0
- Jump SWAP
- Jump DO
- SWAP, Load ONE
- Store IS_SWAP // IS_SWAP = true
- Loadi CURRENT
- Store AUX
- Load NEXT_VAL
- StoreI CURRENT
- Load AUX
- StoreI NEXT
- Jump DO
- // OPTIMIZATION
- CHECK_PRE_END, Load IS_SWAP
- Skipcond 400 // if IS_SWAP == 0 then no elements has been swapped and then we are done
- Jump FORj
- Jump END
- END, Halt
- PRINT, LoadI CURRENT
- Output
- Load CURRENT
- Add ONE
- Store CURRENT
- Load INDEX_I
- Add ONE
- Store INDEX_I
- Load SIZE
- Subt INDEX_I
- Skipcond 400
- Jump PRINT
- Jump END
- SIZE, DEC 0
- ONE, HEX 001
- ZERO, HEX 000
- INDEX_I, DEC 000
- INDEX_J, DEC 000
- START_ADDR, HEX 002
- CURRENT, HEX 001
- NEXT, HEX 000
- NEXT_VAL, DEC 000
- AUX, DEC 000
- IS_SWAP, HEX 000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement