Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- // .data
- short N = 10; // N = 10
- short* p_result = 0x30; // adresa novog niza
- short* p_done = 0x50; // adresa za kraj programa
- short a[10] = {5, 3, 8, 12, 5, 4, -1, 0, 16, 4};
- */
- .data
- 10
- 0x30
- 0x50
- 5, 3, 8, 12, 5, 4, -1, 0, 16, 4
- /*
- // .text
- for(short i=0; i<N; i++)
- {
- if(a[i] > 3) and a[i]%2 == 0)
- *p_result = a[i];
- p_result++;
- }
- *p_done = 1;
- */
- .text
- /*
- Recommended register list:
- R0 - N
- R1 - p_result
- R2 - p_done
- R3 - a[i]
- R4 - a[i] koji zadovoljava uslove
- R5 - i
- R6 - tmp
- R7 - tmp
- */
- begin:
- ld R0,R0 //R0=N
- inc R1,R1
- ld R1,R1 //R1= 0x30
- inc R7,R7
- inc R7,R7
- ld R2,R7 //R2=0X50
- inc R6,R6
- inc R6,R6
- inc R6,R6 //R6=3
- petlja:
- sub R7,R0,R5
- jmpz krajpetlje
- ld R3,R6
- sub R7,R7,R7 //praznjenje
- inc R7,R7 //R7=1 i to je maska
- and R7,R3,R7 //paran broj vraca 0 a neparan vraca 1
- jmpnz naredna
- sub R7,R7,R7 //praznjenje
- inc R7,R7
- inc R7,R7
- inc R7,R7 //R7=3
- sub R7,R7,R3
- jmps dodaj
- inc R6,R6
- inc R5,R5
- jmp petlja
- naredna:
- inc R6,R6
- inc R5,R5
- jmp petlja
- dodaj:
- st R3,R1
- inc R6,R6
- inc R5,R5
- jmp petlja
- krajpetlje:
- sub R7,R7,R7
- inc R7,R7
- st R7,R2
- end:
- jmp end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement