Uživatel:Llavajua

Z MAM wiki

Přejít na: navigace, hledání

Obsah

[editovat] Diferents Operation Loops

The main aim of our project is to make some different operations using assembler of ATtiny2313.

The goal is to obtain which kind of operator are we using and after, show which result are obtaining:

1. Adder operation.

2. Subber operation.

3. Logical shifts:

a) Logical shift to the left.

b) Logical shift to the right.

It is an interpretation of C loops and how to increase, decrease and logical shifts.

We will assemble some C code like this:


[editovat] C code similar to what we will assemble


int main()
{
	i = 0
	
	adder(*i);
	subber(*i);
	mleft(*i);
	mright(*i);
}

void adder(int *i)
{
	PORTD = 1; //We suppose this code is like the assembler "SBI PORTD, VARA" where VARA = 1
	for(int j = 0; j <= 9; j++)
	{
		i++;
		PORTB <<= i; //We suppose this code is like the assembler "OUT PORTB, r30 " where r30 = i
	}
}

void subber(int *i)
{
	PORTD = 2;
	for(int j = 9; j >= 1; j--)
	{
		i--;
		PORTB <<= i; 
	}
}

void mleft(int *i)
{
	...
}

void mright(int *i)
{
	...
}



[editovat] Variable definition:


.include "tn2313def.inc"

           .EQU VARA = 0
           .EQU VARS = 1
           .EQU VARL = 2
           .EQU VARR = 3

MAIN:      LDI r30, 0      // Load number '0' to register r30
           LDI r31, 1      // Load number '1' to register r31
           LDI r29, 9      // Load number '9' to register r29
           LDI r28, 8      // Load number '8' to register r28
           LDI r27, 0      // Load number '0' to register r27
           OUT $18, r30    // Load the value of r30 in the direction $18, its means in PORTB
           RJMP CALLA      // Relative Jump to subroutine CALLA

[editovat] Now we make a Adder:


ADDER:     ADD r30, r31    // Adds the value of r30 to the value r31 and save it in r30
           OUT $18, r30    // Load the value of r30 to the direction of PORTB
           CP r30, r29     // Compare value r29 and r30
           BREQ CALLS      // If this values are equal, then jump to subroutine CALLS
           BRNE ADDER      // Else, return to ADDER

[editovat] Now we make a Subber:


SUBBER:    SUB r30, r31    // Substrate the value of r31 to the value of r30 and save it in r30
           OUT $18, r30    // Load the value of r30 to the direction of PORTB
           CP r30, r31     // Compare the value r30 and r31
           BREQ CALLL      // If are equal, jump to CALLL
           BRNE SUBBER     // Else, return to SUBBER

[editovat] Now we will move our bits to the Left:


MLEFT:     LSL r30         // Move the value of r30 to left
           OUT $18, r30    // Load the value of r30 to the direction of PORTB
           CP r30, r28     // Compare the value r30 and r28
           BREQ CALLR      // If this values are equals, then jump to CALLR
           BRNE MLEFT      // If not, return to MLEFT

[editovat] Now we will move our bits to the Right:


MRIGHT:    LSR r30         // Move the value of r30 to right
           OUT $18, r30    // Load the value of r30 to the direction of PORTB
           CP r30, r27     // Compare the value r30 and r27
           BREQ EXIT       // If this values are equals, then jump to EXIT
           BRNE MRIGHT     // Else, return to MRIGHT

CALLA:     SBI PORTD, VARA
           RJMP ADDER

CALLS:     CBI PORTD, VARA
           SBI PORTD, VARS
           RJMP SUBBER

CALLL:     CBI PORTD, VARS
           SBI PORTD, VARL
           RJMP MLEFT

CALLR:     CBI PORTD, VARL
           SBI PORTD, VARR
           RJMP MRIGHT

EXIT:      NOP


Soubor:Pic2.jpg


Soubor:Pic1.jpg


Soubor:Pic3.jpg


Soubor:Pic4.jpg

Osobní nástroje