; ; UFRGS - INF - M Johann - 2023 - johann@inf.ufrgs.br ; Simple multiplication of pairs of numbers in a vector ; Stores the results after this vector ; ----- DATA org h80 size: db 18 ptr: db 0 vector: dab 2,2,7,5,10,10,12,12,16,16,0,7,7,0,3,3,1,200 result: db 0 ; here goes the result ; calculated after vector ; ----- BEGIN MAIN CODE org 0 startup: ; start by computing where the result goes LDR A,size STR A,ptr ADD A,ptr ; ptr = 2 * size LDR A,#vector ADD A,ptr ; adds vector address STR A,ptr ; and stores result ptr LDR X,#0 ; X is vector index beginmul: LDR A,#0 ; start with 0 STR A,ptr,I ; LDR A,vector,X ; reads operand LDR B,vector+1,X ; reads multiplier loop: JZ next ; multiply loop ended? ADD A,ptr,I ; adds to result STR A,ptr,I ; store result LDR A,vector,X ; recover operand SUB B,#1 ; decrement loop JMP loop next: LDR A,ptr ; increment pointer ADD A,#1 STR A,ptr ADD X,#2 ; next numbers SUB X,size ; size must be exact, even JZ finish ADD X,size JMP beginmul finish: HLT ; END OF FILE