logo Use SA10RAM to get 10%* Discount.
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

Martin DoeStatistics

968 Answers

Hire Me
Bryan ThomsonPsychology

816 Answers

Hire Me
Erlanda AlvesMarketing

818 Answers

Hire Me
Tanusree KunduMathematics

591 Answers

Hire Me
Assembly Programming

The Input/output Peripherals programming and Logic instructions are a central future in many embedded applications


Assignment Three – Input/output and Logic Instructions Programming


The Input/output Peripherals programming, and Logic instructions are a central future in many embedded applications. It is essential for any embedded system programmer being able to access and communicate with IO ports. Embedded system logic instructions are also useful for manipulation of bit strings and for dealing with data at the bit level where only a few bits may be of special interest. Logic instructions programming are essential in dealing with input/output tasks. You may need to modify the embedded system that you built in the previous assignment for the implementation of this assignment. The goal for this assignment is to familiarize yourself with the fundamental skills needed in embedded programming.

Part One

  1. Create an infinite loop that

    1. Reads the binary setting of the 5-bit DIP switch on the board (SW0 – SW4)

    2. Display the value on the 7-segment display

    3. After some delay, display the binary value on the LEDs

Part Two

In this part you will implement a Nios II assembly language program shown. The program counts the longest string of 1’s in a word of data. For example, if the word of data is 0x103fe00f, then the required result is 9. Compile and load the program. Fix any errors that you encounter. Once the program is loaded into memory in the computer, single step through the code to see how the program works.


.global _start

 ldw      r9, TEST_NUM(r0) mov     r10, r0

LOOP: beq      r9, r0, end srli         r11, r9, 0x01 and      r9, r9, r11

addi     r10, r10, 0x01 br    LOOP

END:   br        END

TEST_NUM:    .word 0x3fabedef


Part Three

Perform the following:

  1. Take the code in part two which calculates the number of consecutive 1’s and make it into a subroutine called ONES. Have the subroutine use register r4 to receive the input data and register r2 for returning the


  1. Add more words in memory starting from the label TEST_NUM. You can add as many words as you like, but include at least 10 words. To terminate the list include the word 0 at the end—check for this 0 entry in your main program to determine when all of the items in the list have been processed.


  1. Develop a new main program to call the newly-created subroutine in a loop for every word of data that you placed in memory. Keep track of the longest string of 1’s in any of the words, and display this result in the 7-segment when your program completes execution.

  2. Make sure to use breakpoints or single-stepping in the Monitor Program to observe what happens each time the ONES subroutine is

Part Four

Also, one might be interested in the longest string of 0’s.

Write a new assembly language program to includes two subroutines; one for finding the

largest string of 1’s and another to find the largest string of 0’s. The program should function as

the following:

  1. Longest string of 1’s in a word of data—Display the result into a 7-segment

  2. Longest string of 0’s in a word of data—Display the result into another 7-segment

  • Display the summation of 1 and 2 on the green

Make each calculation in a separate subroutine called ONES, ZEROS, and ALTERNATE. Call each of these subroutines in the loop that you wrote in Part three, and keep track of the largest result for each calculation, from your list of data.

Part Five

To detect errors in data communication and processing, an additional bit is sometimes added to a binary code word to define its parity. Parity may be used with binary numbers as well as with codes, including ACII for characters, and parity bit may be placed in any fixed position in the code. Write a program to read a binary number equivalents for 32 through 47 with a parity bit added in the rightmost position. Include an odd parity to the bytes for each numbers. Numbers with parity bit to be stored in memory at location oddp.

Output the sequences of the parity result at memory location oddp to LEDG to verify the work.

Supporting Notes

The parallel ports that you implemented in your embedded system are to be connected to the 7- segment displays. Figure below shows how the display segments are connected to the parallel ports with the ports’ respective memory mapped addresses.

To show each of the numbers from 0 to 9 it is necessary to light up the appropriate display segments. For example, to show 0 on HEX0 you have to turn on all of the segments except for the middle one (segment 6).

The parallel ports connected to the seven-segment displays, HEX7 − 0, of the DE2-115.

//Subroutine to convert the digits from 0 to 9 to be shown on a HEX display.

//Parameters: r4 = the decimal value of the digit to be displayed

//Returns: r2 = bit pattern to be written to the HEX display

SEG7_CODE: movia r15, BIT_CODES  add      r15, r15, r4 db r2, (r15) ret

BIT_CODES:                .byte    0b00111111, 0b00000110, 0b01011011, 0b01001111, 0b01100110

.byte    0b01101101, 0b01111101, 0b00000111, 0b01111111, 0b01100111

.skip    2          //pad with 2 bytes to maintain word alignment

example of code that shows the contents of registers on the 7-segment displays is illustrated below. Note that this code uses the DIVIDE subroutine that was discussed earlier. The code in the figure shows only the steps needed for register r10. Extend the code to display all three result as specified on the 7-segment displays and LEDs as described above.

// now display r10 on HEX1-0, r11 on HEX3-2 and r12 on HEX5-4

DISPLAY:        movia r8, Insert HEX3-HEX0 base address mov r4, r10            //display r10 on HEX1-0

call      DIVIDE           //ones digit will be in r2; tens digit in r3 mov            r4, r2              //pass ones digit to SEG7_CODE

call      SEG7_CODE

mov     r14, r2            //save bit code

mov     r4, r3              //retrieve tens digit, pass to SEG7_CODE call            SEG7_CODE

slli       r2, r2, 8

or        r14, r14, r2

  • code for r11 (not shown)

stw      r14, (r8)

code for r12 (not shown)

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme

Get Free Quote!

318 Experts Online