Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

If Then statements in Assembly

Status
Not open for further replies.

SamanthaL

Junior Member level 2
Joined
Feb 4, 2009
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,474
Hello all!

Below is a subroutine that is supposed to call different things based on the value of Test_Count. What the code below should be doing is taking Test_Count (which is initialized to 3) and seeing what its value is by subtracting values from it and seeing if the output is zero. It calls Test# which does other stuff then returns. After this, it goes to Continue, where the Test_Count variable is decremented and the subroutine is called again.

The output is only calling Test4. It keeps repeating this without going through the other test cases. Am I doing something wrong with the status register?

Generate_Test_Cases_2
movf Test_Count,W
sublw b'00000011'
btfsc STATUS,Z ; if W = 3,
call Test4
movf Test_Count,W
sublw b'00000010'
btfsc STATUS,Z ; if W = 2,
call Test3
movf Test_Count,W ; W = Test_Count
sublw b'00000001' ; if W = 1;
btfsc STATUS,Z
call Test2
movf Test_Count,W ; W = Test_count
sublw b'00000000'
btfsc STATUS,Z ; if W = 0,
call Test1
bsf PORTC,7 ; MC code is 01
bcf PORTC,6 ; MC now ready to send data
call Wait
goto Continue

Continue
decfsz Test_Count ; Move on to next test case
goto Start ; Reinitialize Test_Count to 3
call Wait
goto Generate_Test_Cases_2
 

Code:
Continue 
    decfsz Test_Count ; Move on to next test case 
    goto Start ; Reinitialize Test_Count to 3 
    call Wait 
    goto Generate_Test_Cases_2
Your condition "decfsz Test_Count" is wrong.
It can be:
Code:
Continue 
    decf Test_Count,F
    btfsc STATUS,Z
    goto Start ; Reinitialize Test_Count to 3 
    call Wait
    goto Generate_Test_Cases_2
But your loop is 1,2,3 only, not 0,1,2,3. Test1 is not realized never. Modify it.
It can be:
Code:
Continue 
    decf Test_Count,F
    movlw b'00000011'
    andwf Test_Count,F
    call Wait
    goto Generate_Test_Cases_2
 

try this software from microchip.... there are some ready usefull assembly functions...

**broken link removed**
 

Some time ago I uploaded in the software uploads/downloads forum a program PicHelp. A utility to generate pic assembler code for common constructs in programming. Using this tool will help you write pic code. Give it a try.

www.elektroda.pl/eboard/viewtopic.php?p=205856
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top