Starting from:
$30

$24

Lab #1 Solution

Quick Links

WTClass Home

My WTClass Tab 1 of 5 (active tab)

Community Groups

Resources

Student Services

Help

2018SP COMPUTER ORG & ASSEM (CS-2325-01) Course-to-Course Navigation Lessons ... RPI -- Startup Labs RPI - Startup Lab 01

Hide Course Menu

2018SP COMPUTER ORG & ASSEM (CS-2325-01)

Course Entry Page

Portal Page for CS 2325

Syllabus

Calendar

Lessons

Resources

WTAMU Library

My Grades

Course Messages

Tools

My Groups

Bits-Bytes 4

Group Homepage: Bits-Bytes 4

CS-2325-01 (CS114829)

Group Homepage: CS-2325-01 (CS114829)

RPI - Startup Lab 01

Assignment

RPI-SL01

Prologue: One advantage to learning assembly on a Linux system is that you have access to the entire C standard library. Any function that can be called from a C program can also be called from assembly. For this lab, you must use the printf and scanf functions from the C standard library. The built-in RPI Linux manual pages provide documentation for all of the functions in the C standard library. The man program can be used to view the documentation from the command line. For example, to read documentation on the scanf() function, simply type man scanf at the command line. The built-in manual also has documentation on itself, which can be read by typing man man at the command line.




Objective: Lead students toward an understanding of the rich resources available to a programmer in a Linux environment.




Assignment:




First step is to create your "remote" repository on thor in the repository named rpi-sl01. That is R, P, I, S, L, 0, 1. You should pay very close attention to the required details for so doing in the work flow document.




Write an ARM assembly language program to accomplish the following:

prompt a user to enter an integer

read an integer from the keyboard into memory

prompt the user to enter another integer

read an integer from the keyboard into memory

load the two integers into CPU registers

add them together

print the result




Create a make file using the Makefile created for the Hello World program as a model. There should be targets for creating the .o file, the executable, and the assembler listing.

Detailed Instructions: Type in the program shown below and verify that it works as expected, then




add another variable, m , using the declaration of n as a template, (requires one assembly directive)

add another format string, fmt3, to serve as a prompt message prior to input of each integer below. This string should be "Please input an integer: " (requires two assembly instructions)

Add another another call to printf to tell the user to input an integer. This should be prior to each call to scanf (see following -- requires two assembler instructions each time)

add another call to scanf, so that your program reads two numbers, m and n , from the user,

(requires three instructions)

before calling printf:

(a) load m into register 1, (requires two instructions)

(b) load n into register 2, (requires two instructions)

(c) add register 2 to register 1 and store the results in register 1 (requires one instruction),

change fmt2 to “The sum is: %d\n”.

revise the commentary prolog to match the revised program's purpose. This comment should also include the names of the team members who collaborated to complete the program.

You will need to use the add instruction. The syntax is: add Rd, Rm, Rn where Rd is the register where you want the result stored, Rm is the register containing the augend, and Rn is the register containing the addend. For example, the instruction add r0, r2, r3 would add the contents of r2 to the contents of r3 and store the result in r0. NOTE that the semantics for the add instruction are the same as the parallel semantics for add on WALL.




C library Input and Output:




The following program demonstrates how to call the printf and scanf functions. Note that scanf will store the input value read in memory and not in a register. After scanf is called, the data must be loaded into a register before it can be used.




/* file rpi-sl01.s

 

A program to input an integer and output same

*/




.extern printf

.extern scanf

.data

fmt1: .asciz "%d" @ format string for reading an int

@ with scanf

.align 2




fmt2: .asciz "You entered %d\n" @ format string for printf

.align 2




n: .word 0 @ memory to store an integer




.text

.globl main

main: push {lr} /* save lr for return to caller */




@ scanf("%d", &n)

ldr r0, =fmt1 /* load address of fmt1 string */

ldr r1, =n /* load address of n */

bl scanf /* call scanf("%d",&n) */




@ printf("You entered %d\n", n)

ldr r0, =fmt2 /* load address of fmt2 string */

ldr r1, =n /* load address of n */

ldr r1, [r1] /* load r1 with what r1 points to */

bl printf /* call printf("You entered %d\n", n) */




mov r0, #0 /* load return value */

pop {lr} /* retrieve return address */

mov pc, lr /* return to caller */

.end




Sumbission: One team member MUST make a statement in this drop box that the project was complete. Work will be verified in your remote git repository for this project.

More products