2017-11-29 3 views
0

LC3 프로그램을 생성하여 양수와 음수를 표시하지만 시뮬레이션 프로그램에서 프로그램을 실행하면 - R5에서 양수는 추가 된 첫 번째 + ve 번호 만 표시합니다. 내 코드는 다음과 같습니다 -이 지점 문 모두가 아주 정확하지LC3 어셈블리를 실행 한 후 레지스터 값이 올바르지 않음

.ORIG x3000 


and r1, r1,#0 ; clear r1 
and r2, r2, #0 ; neg counter amount of negative numbers 
and r3, r3, #0 ; positive counter amount of pos numbers 
and r4, r4, #0; negative sum 
and r5,r5, #0; positive sum 
and r6,r6,#0; clear register 


LEA R1, DATA 



loop    
     ldr r6, r1, #0 
     BRn negativecountm ;if negative go to branch to ncount method 
     BRp positivecountm ;if positive go to branch to pcount method 
     BRz Escape ;if 0 encountered program done go to escape method 


negativecountm 
     add r2, r2, #1 ; increment count for neg numbers 
     add r4, r4, r6 ; sum of neg number 
     add r1, r1,#1 ; increment pointer to point to next number in data 
     BRp loop ; go back to original loop 

positivecountm 
     add r3, r3, #1 ; increment count for positive num 
     add r5, r5, r6; sum of +ve num 
     add r1, r1, #1 ; increment pointer to point to next num in data 
     BRn loop; 


Escape 
     ST r2, negativecount ; 
     ST r3, positivecount; 
     ST r5, positivesum; 
     ST r4, negativesum; 
     TRAP x25 ; 


    DATA  .Fill 1244 
      .Fill -23 
      .Fill 17 
      .Fill 6 
      .Fill -12 
      .Fill 0 


negativecount .BLKW 1 
positivecount .BLKW 1 
positivesum .BLKW 1 
negativesum .BLKW 1 


.END 

답변

1
BRp loop ; go back to original loop 
[...] 
BRn loop; 

LC3/어셈블리를 사용하는 어떤 제안이 새. (즉, LD, 레아, LDR은, LDI는, ADD, AND, NOT한다) 언제 명령이 레지스터에 기록하는 조건 코드가 설정되어 있는지 기억

조건 코드가 당신이 할 때 설정되고있는

add r1, r1, #1 ; increment pointer to point to next num in data 

양수의 경우 반드시 r1에 해당 ADD 명령어 뒤에 음수 값이 포함되지 않습니다.

브랜치를 무조건 분기로 변경하면 문제가 해결됩니다.

그래서 그 대신 BRN의/P 단순히

BR loop 

트릭을 할 것인가 말

.

+0

고맙습니다. – rahulchawla

관련 문제