8085simulator / 8085simulator.github.io

91 stars 57 forks source link

Cube of a 4bit number bug. #11

Open Ce3Pi0 opened 1 year ago

Ce3Pi0 commented 1 year ago

I wrote a program to find the cube of a 4 bit number. Whenever I run it step by step everything works perfectly fine for every test case and there are no problems neither with the program itself nor the result generated. The problem occurs whenever I use the "Run all at a time" button, only when I try to find the cube of 0Fh. For every other case except for this one it also gives the correct answer. The result of the cube of 0Fh shown in the accumulator is F0H for some reason, but when I store it in a memory location or move it to another register, it sees it as E1H (which is the correct result). I've tried troubleshooting this problem and what I think might be happening is that the bits of the accumulator get shifted right by one in the registers GUI, because when I tried to decrement the contents of the accumulator, the left most bit changed from 1 to 0. I am going to attach the code of the program and a few images to further help you diagnose the problem. If the description of the problem that I've provided is not clear enough, feel free to contact me.

Edit: After further examining the problem, I've figured out that whenever the STA instruction gets called when I would use the "Run all at a time" button, the contents of the A register get shifted to the right by one bit.

Program_Error Program_Error_After_Decrement Program_Error_After_Decrement_2

Source code:

           MVI A,0F
           STA 3040
           MOV B,A
           MOV C,A
           MVI A,00

SUM:
ADD B DCR C JNZ SUM

           STA 3050H
           DCR A
           DCR A