assembly language review being able to repeat on the blackfin the things we were able to do on the...

24
Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 06/24/22 Review of 50% OF ENCM369 in 50 minutes 1

Upload: shana-lee

Post on 19-Jan-2018

215 views

Category:

Documents


0 download

DESCRIPTION

Being able to ADD and SUBTRACT the contents of two data registers Blackfin DATA registers R0, R1, R2 and R3 R0 = R1 + R2;// Addition R3 = R1 – R2;// Subtraction It makes sense to ADD and SUBTRACT “values” stored in data registers 2/26/2016 Review of 50% OF ENCM369 in 50 minutes3 / 28

TRANSCRIPT

Page 1: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Assembly Language Review

Being able to repeat on the Blackfin the things we were able to do on the MIPS

05/06/23 Review of 50% OF ENCM369 in 50 minutes 1

Page 2: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Assembly code things to review50% of ENCM369 in 50 minutes Being able to ADD and SUBTRACT the contents of two data

registers Being able to bitwise AND and bitwise OR the contents of two

data registers Being able to place a (small) required value into a data register Being able to place a (large) required value into a data register Being able to write a simple “void” function Being able to write a simple “int” function Being able to ADD and SUBTRACT the contents of two memory

locations

05/06/23 Review of 50% OF ENCM369 in 50 minutes 2 / 28

Page 3: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Being able to ADD and SUBTRACT the contents of two data registers Blackfin DATA registers R0, R1, R2 and R3

R0 = R1 + R2; // Addition R3 = R1 – R2; // Subtraction

It makes sense to ADD and SUBTRACT “values” stored in data registers

05/06/23 Review of 50% OF ENCM369 in 50 minutes 3 / 28

Page 4: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Being able to bitwise AND and OR the contents of two data registers Blackfin DATA registers R0, R1, R2 and R3

R0 = R1 & R2; // Bitwise AND R3 = R1 | R2; // Bitwise OR

It makes sense to perform OR and AND operations on “bit-patterns” stored in data registers.

NEVER perform ADD and SUBTRACT operations on “bit-patterns” stored in data registers. (Although SOMETIMES get the correct answer – code defect)

05/06/23 Review of 50% OF ENCM369 in 50 minutes 4 / 28

Page 5: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Is it a bit pattern or a value?Hints from “C++”If the coder is consistent when writing the code then Bit patterns are normally stored as “unsigned integers” e.g.

unsigned int bitPattern = 0xFFFFFFFF

Values are normally stored as “signed integers” e.g.

signed int fooValue = -1; or int fooValue = -1; where the word “signed” is understood as being there although not actually written.

Note that “bitPattern” and “fooValue” are stored as the SAME bit pattern 0xFFFFFFFFF in the registers and memory

05/06/23 Review of 50% OF ENCM369 in 50 minutes 5 / 28

Page 6: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Being able to place a required value into a data register –1 Like the MIPS, the Blackfin uses 32 bit instructions – all

the same size to ensure maximum speed (highly pipelined).

The 32 bit Blackfin instruction for placing a value into a data register has been designed to have16 bits available for describing the instruction and 16 bits for describing the “signed” 16 bit value to be put into a “signed” 32 bit data register.

This means that you have to use “2” 32-bit instructions to put large values into a data register

05/06/23 Review of 50% OF ENCM369 in 50 minutes 6 / 28

Page 7: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Placing a value into a data register R1 = 0; legal -- 0 = 0x0000 (signed 16

bits); (becomes the signed 32 bit 0x00000000 after auto sign extension)

R0 = 33; legal -- 33 = 0x0021 (signed 16 bits) (becomes the signed 32 bit 0x00000033 after auto sign extension)

R2 = -1; legal -- -1 = 0xFFFF (signed 16 bits) (becomes the signed 32 bit 0xFFFFFFFF after auto sign extension)

R3 = -33; legal -- -33 = 0xFFDE (signed16 bits) (becomes the signed 32 bit 0xFFFFFFDE after auto sign extension)

05/06/23 Review of 50% OF ENCM369 in 50 minutes 7 / 28

Page 8: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Placing a “large” value into a data register This approach does not work for any “large” value

R1 = 40000;

illegal -- as 40000 can’t be expressed as a signed 16-bit value – it is the positive 32 bit value 0x00009C40

If the assembler tried to take the bottom 16 bits of the decimal 40000 and sign extend it then this would happen “16-bit” hex value 9C40 (1001 1100 0100 0000) becomes “32-bit” hex value after sign extension 0xFFFF9C40 which is a “negative value”

Therefore it is “illegal” to try to put a 32-bit value directly into a register; just as it would be illegal to try in MIPS.

05/06/23 Review of 50% OF ENCM369 in 50 minutes 8 / 28

Page 9: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Placing a “large” value into a data register If the assembler tried to take the bottom 16 bits of the decimal 40000

and sign extend it then this would happen “16-bit” hex value 9C40 (1001 1100 0100 0000) becomes “32-bit” hex value after sign extension 0xFFFF9C40 which is a “negative value”

“illegal” just as it would be in MIPS

// Want to do R1 = 40000 // Instead must do operation in two steps as with MIPS R1.L = lo(40000); // Tell assembler to put “bottom” // 16-bits into “low” part of R1 register R1.H = hi(40000); // Tell assembler to put “top” // 16-bits into “high” part of R1 register

05/06/23 Review of 50% OF ENCM369 in 50 minutes 9 / 28

Page 10: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Placing a “large” value into a data register A common error in the laboratory and exams is getting this two step

thing “wrong”

// Want to do R1 = 41235 R1.L = lo(41235); // “bottom” 16-bits into “low” part of R1 register R1.H = hi(41325); // “top” 16-bits into “high” part of R1 register

RECOMMENDED SYNTAX TO AVOID “CODE DEFECTS”#define LARGEVALUE 41235 // C++ - like syntax

R1.L = lo(LARGEVALUE); R1.H = hi(LARGEVALUE);Yes -- this assembler allows you to put multiple Blackfin assembly language

instructions on one line – NOTE the syntax

05/06/23 Review of 50% OF ENCM369 in 50 minutes 10 / 28

Page 11: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Being able to write a simple “void” function void SimpleVoidASM(void)#include <macros.h>#define <defBF533.h>

.section program; .global _SimpleVoidASM__Fv;_SimpleVoidASM__Fv:

_SimpleVoidASM__Fv.END: RTS;

05/06/23 Review of 50% OF ENCM369 in 50 minutes 11 / 28

Things in red were cut-and-pasted using the editor

Page 12: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Being able to write a simple “int” function int SimpleIntASM(void)#include <macros.h>#define <defBF533.h>

.section program; .global _SimpleIntASM__Fv;_SimpleIntASM__Fv:

R0 = 7; // Return “7”_SimpleIntASM__Fv.END: RTS;05/06/23 Review of 50% OF ENCM369 in 50 minutes 12 / 28

Things in red were cut-and-pasted using the editor

Page 13: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Being able to ADD and SUBTRACT the contents of two memory locationsLet’s set up a practical situation A “background” thread is putting values into

an array. For “background” thread read “interrupt service

routine” or ISR. ISR work “in parallel” with the “foreground”

thread that is doing the major work on the microprocessor

Write a subroutine (returns int) that adds together the first two values of the array

05/06/23 Review of 50% OF ENCM369 in 50 minutes 13 / 28

Page 14: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Start with a copy of the “int” function int SimpleIntASM(void)#include <macros.h>#define <defBF533.h>

.section program; .global _SimpleIntASM__Fv;_SimpleIntASM__Fv:

R0 = 7; // Return “7”_SimpleIntASM__Fv.END: RTS;05/06/23 Review of 50% OF ENCM369 in 50 minutes 14 / 28

Things in red were cut-and-pasted using the editor

Page 15: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Modify to be int AddArrayValuesASM(void)#include <macros.h>#define <defBF533.h>

.section program; .global _AddArrayValuesASM__Fv;_AddArrayValuesASM __Fv:

R0 = 7; // Return “7”_AddArrayValuesASM __Fv.END: RTS;05/06/23 Review of 50% OF ENCM369 in 50 minutes 15 / 28

Things in red were cut-and-pasted using the editor

Page 16: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Add a “data” array

#include <macros.h>#define <defBF533.h>

.section L1_data;.byte4 _fooArray[2];

.section program; .global _AddArrayValuesASM__Fv;_AddArrayValuesASM __Fv:

R0 = 7; // Return “7”_AddArrayValuesASM __Fv.END: RTS;

05/06/23 Review of 50% OF ENCM369 in 50 minutes 16 / 28

Things in red were cut-and-pasted using the editor

Page 17: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Plan to return “sum”, initialize sum to 0

#include <macros.h>#define <defBF533.h>

.section L1_data;.byte4 _fooArray[2];

.section program; .global _AddArrayValuesASM__Fv;_AddArrayValuesASM __Fv:

#define sum_R0 R0 // register int sum;sum_R0 = 0; // sum = 0;

_AddArrayValuesASM __Fv.END: RTS;

05/06/23 Review of 50% OF ENCM369 in 50 minutes 17 / 28

Things in red were cut-and-pasted using the editor

Page 18: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Place the memory address of the start of the array into a pointer register…. Other code

.section L1_data;.byte4 _fooArray[2];

.section program; .global _AddArrayValuesASM__Fv;_AddArrayValuesASM __Fv:#define sum_R0 R0 // register int sum;

sum_R0 = 0; // sum = 0;

#define pointer_to_array_P0 P0 // register int * pointer_to_arrayP0.L = lo(_fooArray); P0.H = hi(_fooArray);

// pointer_to_array = &fooArray[0];

_AddArrayValuesASM __Fv.END: RTS;

05/06/23 Review of 50% OF ENCM369 in 50 minutes 18 / 28

Things in red were cut-and-pasted using the editor

Page 19: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Read the contents of the first array location into register R1 and add to sum_R0; …. Other code

.section L1_data;.byte4 _fooArray[2];

.section program; .global _AddArrayValuesASM__Fv;_AddArrayValuesASM __Fv:#define sum_R0 R0 // register int sum;

sum_R0 = 0; // sum = 0;

#define pointer_to_array_P0 P0 // register int * pointer_to_arrayP0.L = lo(_fooArray); P0.H = hi(_fooArray); // pointer_to_array = &fooArray[0];R1 = [pointer_to_array_P0]; // int temp = fooArray[0]; sum_R0 = sum_R0 + R1; // sum = sum + temp

_AddArrayValuesASM __Fv.END: RTS;

05/06/23 Review of 50% OF ENCM369 in 50 minutes 19 / 28

Things in red were cut-and-pasted using the editor

Page 20: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Read the contents of the second array location into register R1 and add to sum_R0; …. Other code

.section L1_data;.byte4 _fooArray[2];

.section program; .global _AddArrayValuesASM__Fv;_AddArrayValuesASM __Fv:#define sum_R0 R0 // register int sum;

sum_R0 = 0; // sum = 0;

#define pointer_to_array_P0 P0 // register int * pointer_to_arrayP0.L = lo(_fooArray); P0.H = hi(_fooArray); // pointer_to_array = &fooArray[0];R1 = [pointer_to_array_P0]; // int temp = fooArray[0]; sum_R0 = sum_R0 + R1; // sum = sum + temp

R1 = [pointer_to_array_P0 + 4]; // temp = fooArray[1]; sum_R0 = sum_R0 + R1; // sum = sum + temp

_AddArrayValuesASM __Fv.END: RTS;

05/06/23 Review of 50% OF ENCM369 in 50 minutes 20 / 28

Things in red were cut-and-pasted using the editor

Page 21: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Add the code into an .ASM file in Assignment 1 and check syntax

05/06/23 Review of 50% OF ENCM369 in 50 minutes 21 / 28

Page 22: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Fix syntax – and run some testsit

05/06/23 Review of 50% OF ENCM369 in 50 minutes 22 / 28

Page 23: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Assignment 1, Q1Demo answer

05/06/23 Review of 50% OF ENCM369 in 50 minutes 23 / 28

Page 24: Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1

Assembly code things to review50% of ENCM369 in 50 minutes Being able to ADD and SUBTRACT the contents of two data

registers Being able to bitwise AND and bitwise OR the contents of two

data registers Being able to place a (small) required value into a data register Being able to place a (large) required value into a data register Being able to write a simple “void” function Being able to write a simple “int” function Being able to ADD and SUBTRACT the contents of two memory

locations

05/06/23 Review of 50% OF ENCM369 in 50 minutes 24 / 28