+1 (315) 557-6473 

Simple Calculations in ARM Assembly Language Assignment Solution.


Instructions

Objective

Write an ARM assignment program that helps us to perform simple calculations in ARM assembly language.

Requirements and Specifications

Your program will simulate operation of a Furniture Factory saw.

A Furniture Factory has an automatic saw that cuts 1" x 6" x 12' planks to the length specified by the user. The saw is preloaded with three full length boards. If the first board is long enough, cut the desired length from the board. If the first board is not long enough, continue checking the other boards until you find one long enough. The user enters the length in whole inches. 144” is the maximum length request and 6" is the minimum length request. Continue prompting the user until all the boards are at least 6" long. After each board is cut the program is to print out the total number of boards cut so far, the total linear length of the boards cut (in inches) and the length remaining on each of the three boards. Prior to shutting down the program the remaining inventory is calculated and displayed as waste. When the program starts it shall display an identification and the current inventory level.

The program shall then prompt the user for the length of board to cut. For example: 

Enter the length of board to cut in inches (at least 6 and no more than 144):

The program shall reject any invalid inputs (characters, less than 6, or greater than 144) and  prompt for entry again.When a valid input is provided the program finds a board that is long enough and cuts therequested length from the board. If there is not a board long enough the program displays there are no boards long enough and prompts for a new (shorter) request. After each valid board cut the current inventory levels are displayed. For example:

Boards cut so far: 4

Liner length of boards cut so far: 75 inches

Current Board Lengths:

One: 69 inches

Two: 144 inches

Three: 144 inches

When the length of each board is less than 6 inches the program will display final inventory levels and return control to the OS.

For example:

Boards cut so far: 30

Liner length of boards cut so far: 423 inches

Current Board Lengths:

One: 4 inches

Two: 0 inches

Three: 5 inches

Inventory levels have dropped below minimum levels and will now terminate.

Waste is 9 inches.

Screenshots of output

program to perform simple calculations in ARM assembly language program to perform simple calculations in ARM assembly language 1 program to perform simple calculations in ARM assembly language 2

Source Code

@ Class:

@ Term:

@ Author:

@ Date:      July 15, 2021

@ Purpose of software:

@ The program simulates the operation of a Furniture Factory Saw

.text

@ Read only data

titlemsg:      .string "Cut-It-Up Saw\n"

boardsmsg:      .string "\nBoards cut so far: %d\n"

lengthmsg:      .string "Linear length of boards cut so far: %d inches\n"

curlenmsg:      .string "Current Board Lengths:\n"

len1msg:      .string "One:      %d inches\n"

len2msg:     .string "Two:     %d inches\n"

len3msg:      .string "Three:     %d inches\n\n"

promptmsg:      .string "Enter the length of board to cut in inches (at least 6 and no more than 144):\n"

minlvlmsg:      .string "\nInventory levels have dropped below minimum levels and will now terminate.\n"

wastemsg:      .string "Waste is %d inches.\n"

badlenmsg:      .string "Not enough inventory to perform cut. Enter new smaller length.\n"

invlenmsg:      .string "Invalid input. Please try again.\n"

intinput:      .string "%d"

@ Main function

.balign 4

.global main

.type main, %function

main:

@ save registers on stack

push {fp, lr}

mov fp, sp

@ allocate space for variables

sub sp, sp, #32

@ initialize variables

mov r0, #144

str r0, [sp, #0]      @ board 1 length = 144

str r0, [sp, #4]      @ board 2 length = 144

str r0, [sp, #8]      @ board 3 length = 144

mov r0, #0

str r0, [sp, #12]      @ boards cut = 0

str r0, [sp, #16]      @ linear length = 0

@ print the title

ldr r0, =titlemsg

bl printf

@ start of cut loop  

cutLoop:

@ print current inventory 

ldr r0, =boardsmsg

ldr r1, [sp, #12]      @ load number of cuts

bl printf

ldr r0, =lengthmsg 

ldr r1, [sp, #16]     @ load linear length

bl printf

ldr r0, =curlenmsg

bl printf

ldr r0, =len1msg

ldr r1, [sp]      @ load length1 length

bl printf

ldr r0, =len2msg

ldr r1, [sp, #4]     @ load length2 length

bl printf

ldr r0, =len3msg

ldr r1, [sp, #8]      @ load length3 length

bl printf

mov r1, #0     @ try board 0 

@ Loop to check that all boards have enough length

checkLoop:

ldr r0, [sp, r1, lsl #2]     @ load length

cmp r0, #6      @ if len >=6, it's ok

bge readLoop

add r1, r1, #1     @ increment board

cmp r1, #3      @ repeat while board < 3

blt checkLoop

@ not enough lengths

@ print program termination 

ldr r0, =minlvlmsg

bl printf

b endCut      @ terminate cuts

@ Loop to read input length to cut, repeat while not valid range

readLoop:

@ prompt user to enter input 

ldr r0, =promptmsg

bl printf

readInt:

@ read integer from user

nbsp;   ldr r0, =intinput

add r1, sp, #20      @ save in stack

bl scanf

@ test for valid integer 

cmp r0, #1      @ if 1 integer was read

beq testValid

@ Loop until enter is found 

readEnter:

bl getchar

cmp r0, #10

bne readEnter

b inputError     @ error

testValid:

@ test for valid input

ldr r0, [sp, #20] n>

cmp r0, #6      @ < 6 is error

blt inputError

cmp r0, #144     @ > 144 is error

ble inputOk

inputError:

@ print error

ldr r0, =invlenmsg

bl printf

b readLoop     @ repeat loop

inputOk: 

mov r2, #0     @ try board 0 

@ Loop to find board to cut

findLoop:

ldr r1, [sp, r2, lsl #2]     @ load length

@ check if length fits 

cmp r0, r1      @ if len <= board len, we found it

ble found

add r2, r2, #1      @ increment board 

cmp r2, #3      @ repeat while board < 3

blt findLoop

@ no board is long enough, ask for new length 

@ prompt user to enter input 

ldr r0, =badlenmsg

bl printf

b readInt      @ read input

found: @ make cut by updating lengths

sub r1, r1, r0      @ subtract required length from board

str r1, [sp, r2, lsl #2]     @ update board length

@ increment number of cuts 

ldr r3, [sp, #12]

add r3, r3, #1

str r3, [sp, #12]

@ increment linear length by requested cut 

ldr r3, [sp, #16]

add r3, r3, r0

str r3, [sp, #16]

b cutLoop      @ repeat to show result

endCut: 

@ calculate waste

ldr r0, [sp] @ load length 1

ldr r1, [sp, #4] nbsp;    @ load length 2

add r1, r1, r0

ldr r0, [sp, #8]      @ load length 3

add r1, r1, r0

@ print waste 

ldr r0, =wastemsg

bl printf

@ terminate program 

mov sp, fp

pop {fp, lr}      @ restore registers

bx lr      @ return to os

@ allocate space for variables@ Read only datainputOk: