Here is the question from assessed exercise as below. Even though I found and summarize the answer from the web, I still don't figure out how it works in Java programming which can assist a fresh learner to understand the logic and hence I am more likely to convert it to assembly language in Sigma 16 system.
Q: A Sigma16 system has an array, X , of 16-bit signed numbers in memory. Write an assembly language program to write a second array, Y whose ith element is 0 if the ith element of X is even and 1 if it is odd.
Ans:
ADD R1, R0, R0 ; i = 0
LEA R2, 4[R0] ; R2 = 4
LEA R3, 1[R0] ; R3 = 1
LEA R4, 2[R0] ; R4 = 2
Loop LOAD R5, X[R1] ; R5 = x[i]
DIV R6, R5, R4 ; x[i] / 2
STORE R15, Y[R1] ; y[i] = x[i] mod 2
ADD R1, R1, R3 ; i++
CMPLT R15, R1, R2 ; If i< 4 then⋯
JUMPT R15, Loop[R0] ; Loop
TRAP R0,R0,R0
Your answers are highly appreciated. Please also correct the above codes if they are way biased with errors.