程序代写代做代考 clock go assembly Lab 5: Simple Output

Lab 5: Simple Output
Objectives
In this assignment, you will write a simple ARMv8 assembly program, assemble it and execute it on the Logisim simulator. By setting GPIO registers, you will make the LED blink. This assignment will introduce you to performing memory mapped I/O, controlling the GPIO registers of the SoC used in this lab, and using instructions of the ARMv8 architecture.
Submission
Prepare your report electronically, using the uploaded template in canvas.
In your report, include your answers to questions found throughout this page (they are highlighted this way, so you can spot them easily). Upload your report, as well as your “lab5.s” file through Canvas.
Preparation
Please refer to the following link for an overview of Memory-mapped I/O and GPIO:
https://unh.box.com/s/adb2v013hakttlb9on1jfq5uh087sdle
Download the updated newproject.sh script here:
https://unh.box.com/s/t69fmb4szbyt1vmlv65kzbapxauneca1
Create project lab5, using this script as you have in the previous lab: switch into the directory where you want to create the project directory and run this script:
./newproject.sh lab5
You can use the same runeclipse.sh file to open your project in Eclipse:
./runeclipse.sh lab5
https://github.com/mkayaalp/logisim-evolution/releases/
If you don’t have Logisim-evolution in your system, then download the latest version of Logisim-evolution from the following link:

Step 1: Testing GPIO in GPIO sub-circuit
Open the following Logisim circ file in Logisim:
https://unh.box.com/s/3w4p442eh9a52jfmag5kjff47i9jvwhe
This circuit implements a small subset (~20 instructions) of the ARMv8 architecture, as well as part of the GPIO registers of the BCM2837 SoC.
The GPIO registers are “mapped” to a part of the memory address space. You can look at the
“Memory Controller” sub-circuit to see how this is implemented (double-click on the “MemoryController” on the left pane). By checking the top 40 bits of the memory address, it decides whether the access is to the data memory or to a peripheral. If so, the bottom 24 bits of the address are compared against the range of addresses for the GPIO registers. The images below show only the relevant parts:
On the bottom right corner of the main circuit, find the box labeled “GPIO”. Notice how bits 5 and 6 of the GPIO_OUT signal is driving LEDs labeled RED_LED and GREEN_LED. This mirrors the setup used in the real lab.
Double-click on the “GPIO” circuit on the left pane to open the sub-circuit. Examine how GPFSELn registers are implemented. The column of S-R flip-flops implement the “Output State” for GPIO pins. Notice that there are 54 pins (0 through 53), and 54 S-R flip flops for driving each bit of the GPIO_OUT signal. Find the flip-flops that are connected to bits 5 and 6 and toggle their contents (using the Poke tool).
The output of the flip-flops should switch to light green, however, the tristate buffers prevent these signals from propagating (the output is shown as blue). Trace the control inputs of the tristate buffers for bit 5 and 6 (click with poke tool to highlight a wire) to determine why they are zero, and how you could change it to one.

You should find a series of AND gates with three inputs. These gates check the corresponding FSELx bits (coming from GPFSELn registers) for a specific combination which configures the GPIO pin as an “output” pin.
Include in your report (Q1): What is the 3-bit value that would make the output of these AND gates to be 1? Can you modify the contents of the GPFSEL0 register (click with poke tool and type the hex value), so that only pin 5 and 6 are configured as outputs? What is the value of GPFSEL0 now? Write this number in binary in your report and highlight the bitfields FSEL5 and FSEL6.
With FSEL5 and FSEL6 set to the correct values, you will see the contents of the S-R flip-flops are propagated to the GPIO_OUT signal and changing the flip-flops would change to
corresponding bits in GPIO_OUT. With both bits 5 and 6 set to 1, go back to the main circuit (Simulate -> Go Out To State -> main) to see that both LEDs are turned on.
In your program, you will achieve this by writing to GPSETn and GPCLRn registers to change the S-R flip-flops. Back in GPIO sub-circuit, trace the S inputs of the flip-flops back to GPSETn registers.
Include in your report (Q2): Click on GPSET0 and enter 40 (hex). Toggle the clock. Go back to the main circuit. Do you see the green LED is switched on? Get back to the GPIO circuit, change the value for GPSET0 to 20 (hex). Did you see the red LED switch on? Write these numbers in binary in your report and show which bits are 1.
Include in your report (Q3): What would you expect to see when you enter the same values to GPCLR0? Enter and confirm.
Include in your report (Q4): Find the value that you would need to enter into GPSET0 or GPCLR0 to switch both LEDs on or off at the same time, test it, and include it in your report.
Make the following list before writing your program.
• A: The address of GPFSEL0
• B: The value you needed to put in GPFSEL0 (Q1 above)
• C: The address of GPSET0
• D: The value to write into GPSET0 to turn the green LED on (Q2 above)
• E: The value to write into GPSET0 to turn the red LED on (Q2 above)
• F: The address of GPCLR0
• G: The value to write into GPLCR0 to turn the green LED off (Q3 above)
• H: The value to write into GPCLR0 to turn the red LED off (Q3 above)

Step 2: Testing GPIO via manually setting register
values
Now that you know the addresses of the relevant registers and the correct values to write into them, you can create an assembly program in “lab5.s” that has the following outline (we will blink only the green LED for now):
.global _start
.type _start, @function
_start:
.L1:
// This is to set LR to a proper value,
// so that we don’t get errors from the debugger. BL main
// We won’t return from main.
// But in case we do, the processor should wait in a loop. B .L1
.global main
.type main, @function
// Write the value B into GPFSEL0 (address: A)
// Write the value D into GPSET0 (address: C) to turn the green LED on
main:
loop:
// Write the value G into GPCLR0 (address: F) to turn the green LED off B loop
Since ARMv8, like mostRISC(Links to an external site.)architectures, is aload-store architecture (Links to an external site.), in order to write a value into a memory address, we need to first put both the value and the address into registers. So, we can detail the outline of “main” a little bit:

main:
loop:
// Write the address of GPFSEL0 (address: A) into X0 // Write the value B into X1
STUR W1, [X0]
// Write the address of GPSET0 (address: C) into X2 // Write the value D into X3
STUR W3, [X2]
// Write the address of GPCLR0 (address: F) into X4 STUR W3, [X4]
B loop
The STUR W1, [X0] instruction writes the 32-bit value in the bottom half of X1, to the address specified in X0. The reason we must use W here, is that we are modifying GPIO registers via memory instruction and the registers we are modifying are 32-bit registers, as you can see on the SoC datasheet.
(Since D is equal to G, we did not need to set another register.)
We can test this program before filling in the necessary instructions for the comments, by manually setting the registers X0 through X4 in the simulator.
Save “lab5.s” and build your program. This will create two files: “lab5.txt” and “lab5.lss”.
Perhaps, you haven’t used the latest version of “newproject.sh”. You can manually change your Makefile, to add the following rules:
lab5.bin: lab5.elf
aarch64-none-elf-objcopy -O binary lab5.elf lab5.bin
lab5.txt: lab5.bin
echo “v3.0 hex words addressed” > lab5.txt
xxd -o 0x80000 -g 1 lab5.bin | cut -c 3-57 >> lab5.txt
lab5.lss: lab5.elf
aarch64-none-elf-objdump -d -j .text lab5.o > lab5.lss

Also change the “all” rule:
all: lab5.ihex as
all: lab5.ihex lab5.txt lab5.lss and change the “clean” rule:
as:
clean:
rm -f lab5.{o,elf,ihex}
clean:
rm -f lab5.{o,elf,ihex,txt,lss}
After saving this, you might need to run Project -> Clean, before building.
Open the main circuit in Logisim and right-click on the instruction memory and select “Load Image…”, locate and select “lab5.txt”. This will load the machine code into the simulator.
To better track the execution similar to a debugger, you can open the “Assembly viewer” window from the “Simulate” menu. From “File” -> “Open lss file”, locate and select “lab5.lss” file to view the assembly instructions. This viewer simply highlights the current instruction using the value of the PC register (the register selected at the top).
Click on the “Reset” button in the circuit using the poke tool to set the PC to 80000 (hex), which is where the program is loaded in instruction memory.
Before starting the execution of your program, go into the ‘RegisterFile” sub-circuit and modify the register contents. Enter the appropriate values into X0, X1, X2, X3, and X4 by clicking on
them with the poke tool and typing the hexadecimal value.
Once you are done, start toggling the clock signal to execute your instructions one by one and verify that your program would work when the registers are initialized properly.
As you are executing these instructions, you can go into, and out of sub-circuits to analyze the signals. Also, various LEDs and “probes” (yellow boxes) placed over the sub-circuits show information about the signals for the current instruction. In addition, clicking on the “State” pane on the left will show you the values of all registers (X0 through X30, and PC).
Include in your report (Q5): Which values did you use to initialize these registers?

Step 3: Blinking the LED programmatically
Now, you need to put the instructions in your program to initialize the registers. You already know how to write a small value into a register. You can set it to zero, then use either ADD to set it to the value you want (e.g. ADD X0, X0, #5). But the I-type instructions allow you to use only 12-bit values.
One trick to setting a register to a large value, is to set it piece-by-piece. You can add one of the 12-bit parts, then shift the register left by 12, then add the next 12-bit part and so on. For
example:
// Set X0 as 0xaaabbbccc
SUB X0, X0, X0
ADD X0, X0, #0xaaa
LSL X0, X0, #12
ADD X0, X0, #0xbbb
LSL X0, X0, #12
ADD X0, X0, #0xccc
Using this method, write the instructions that would initialize the registers properly to complete your program. Simulate your program by stepping through the instructions to verify that it works. Remember to reload the “txt” and “lss” files and click on the “Reset” button every time you build your program.
Include in your report (Q6): Make sure to include the contents of “lab5.s” in the end of your report AND ALSO submit the “lab5.s” file together with your report.
Include in your report (Q7): Select a tick frequency of 4 Hz and enable the ticks. At what frequency does the LED blink? If you were running this program on a real processor with many MEGAHz of clock frequency, how long would the LED stay ON at a time? In your report explain,
how you could achieve a slow blinking LED on a very fast processor.