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.

[SOLVED] Can someone translate this simple assembly to C?

Status
Not open for further replies.

skyassasin16

Junior Member level 2
Junior Member level 2
Joined
Jan 10, 2011
Messages
24
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,453
I'm a complete beginner in mikroC, I'm programming a PIC16, please translate this part of asm to C.

START: BTFSS PORTB, 0
GOTO START
GOTO LOOP
LOOP: NOP
BSF PORTC, 1
CALL DELAY_MS
BCF PORTC, 1
GOTO LOOP

thanks, dunno If I am posting in a wrong forum, so I apologize, im a newbie
 

The command btfss tests a bit, and skips the next instruction if that bit is equal to 1.

you are checking the status of portB, and if zero proceed or execute go to start
Loop:NOP gives 1 machine cycle delay

BSF—Bit Scan Forward
Searches the source operand (second operand) for the least significant set bit (1 bit). If a least significant 1 bit is found, its bit index is stored in the destination operand (first operand). The source operand can be a register or a memory location; the destination operand is a register. The bit index is an unsigned offset from bit 0 of the source operand. If the contents source operand are 0, the contents of the destination operand is undefined.
 

I am sorry mister, but I need the syntax to C, not the description of each. thanks anyways.
 

There are some things which i have assumed during the conversion, see the comments

START: BTFSS PORTB, 0
GOTO START
GOTO LOOP
LOOP: NOP
BSF PORTC, 1
CALL DELAY_MS ; in this code DELAY_MS subroutine is not defined, i assume that u have defined it...
BCF PORTC, 1
GOTO LOOP

Here is a possible C code, To run this code u must use CCS Info (PIC C) compiler.

// code starts here
while(PIN_B0);
// loop starts here
while(TRUE) {
output_high(PIN_C1);
delay_ms(1000); // 1 sec delay which i assumed earlier
output_low(PIN_C1);
}
// code ends here

personally this is the right forum, but i advise u to join a group (PIC Microcontrollers), u can get many help there...

Regardz
Ayaz Ahmed
 
Hi;

Ayaz's translation is nice but has a little mismatch (at begin):

Modify the first C line
// code starts here
while(PIN_B0); //infinite loop while PIN_B0==1
to
while(PIN_B0==0); //infinite loop while PIN_B0==0

because the original assemby loop was:
START:
BTFSS PORTB, 0 ;means: Bit Test portb,0 and Skip the next instruction if it is Set (equal to 1)
GOTO START
 

Thanks for the quick response, I get the logic. One more question, does the syntax in CCS Info (PIC C) compiler is the same as in mikroC?
 

The command btfss tests a bit, and skips the next instruction if that bit is equal to 1.
...
BSF - Bit Scan Forward
...

Hi ckshivaram;

Sorry but your explanation above is about the X86's BSF instruction.

The PIC's BSF is a simple Bit Set of a register File (in RAM) ...
 
I'm a complete beginner in mikroC, I'm programming a PIC16, please translate this part of asm to C.
newbie

HI skyassasin16
This is mikroC pro code. 16f877a

void main(){
TRISB0_bit=1; //PORTB0 set to input
TRISC1_bit=0; //PORTC1 set to output
PORTB=0;
PORTC=0;
while(PORTB==0);
while(1){
PORTC.F1=1; //PORTC1 set to high
Delay_ms(200);
PORTC.F1=0; //PORTC1 set to low
Delay_ms(200);

}
}
 
Last edited:
So much thanks guys! Now I can finally mark this as solved!! ;)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top