Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do I change the code below to fit the instructions given here? Write an ARM

ID: 3742598 • Letter: H

Question

How do I change the code below to fit the instructions given here?

Write an ARM program that asks the user to enter an upper and lower limit numbers (as positive integers). The program will:

1. Verify that both numbers are positive.

2. Verify that the upper limit is greater than the lower limit.

3. Verify that the difference between the upper and lower limit is no greater than 50.

4. As required print out an error message which is specific to the nature of the input error checks in 1-3. After printing the error message terminate the program.

5. Print from the lower limit to the upper limit incrementing by 1.

6. Print the sum of the numbers from the lower limit to upper limit (inclusive). After printing the final sum terminate the program.

As with all programs your outputs should be clearly labeled and your code generous documented.

@-----------------------------------------------------------

@ Start instruction section

.text

.global main

main:

@ Use printf to print input prompt

LDR r0, =input_promptL @ string to print needs to be in r0

BL printf @ call printf

@ use scanf to read an integer from the user

@ r0 must contain address of the input format string

@ r1 must contain address of the variable where input will be stored

LDR r0, =input_format

LDR r1, =intval

BL scanf @ call scanf

@ Move the value to print into r1

LDR r2, =intval

LDR r1, [r2]

@ Add one to the int to show it is a numeric value

ADD r1, r1, #1

r0 = output_formatL

@ Load the output format string

@ Value to print is already in r1

@ Print the values between the upper limits in increments of 1

LDR r0, =output_format

BL printf @ call printf

ADR r0, r1

LDR r0, [r2] @r0 := N

MOV r1, #1

CMP r1, r0

@BGE after something

ADD r1, r1, #1

@B r1, r0

@ exit the program

MOV r7, #1

SVC 0

@--------------------------------------------------

@ Start data section

.data

input_promptL: .asciz "Enter a Lower Limit: "

input_promptU: .asciz "Enter an Upper Limit: "

output_formatL: .asciz "Lower Limit: %d: "

output_formatU: .asciz "Upper Limit: %d: "

input_format: .asciz "%d"

.align 4

@ Set aside space for an integer

intval: .word 0

Explanation / Answer

Answer:

.LC0:

.string "Enter two numbers(intervals): "

.LC1:

.string "Prime numbers between "

.LC2:

.string " and "

.LC3:

.string " are: "

.LC4:

.string " "

main:

push rbp

mov rbp, rsp

sub rsp, 16

mov esi, OFFSET FLAT:.LC0

mov edi, OFFSET FLAT:_ZSt4cout

call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

lea rax, [rbp-12]

mov rsi, rax

mov edi, OFFSET FLAT:_ZSt3cin

call std::basic_istream<char, std::char_traits<char> >::operator>>(int&)

mov rdx, rax

lea rax, [rbp-16]

mov rsi, rax

mov rdi, rdx

call std::basic_istream<char, std::char_traits<char> >::operator>>(int&)

mov esi, OFFSET FLAT:.LC1

mov edi, OFFSET FLAT:_ZSt4cout

call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

mov rdx, rax

mov eax, DWORD PTR [rbp-12]

mov esi, eax

mov rdi, rdx

call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

mov esi, OFFSET FLAT:.LC2

mov rdi, rax

call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

mov rdx, rax

mov eax, DWORD PTR [rbp-16]

mov esi, eax

mov rdi, rdx

call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

mov esi, OFFSET FLAT:.LC3

mov rdi, rax

call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

.L7:

mov edx, DWORD PTR [rbp-12]

mov eax, DWORD PTR [rbp-16]

cmp edx, eax

jge .L2

mov DWORD PTR [rbp-8], 0

mov DWORD PTR [rbp-4], 2

.L5:

mov eax, DWORD PTR [rbp-12]

mov edx, eax

shr edx, 31

add eax, edx

sar eax

cmp DWORD PTR [rbp-4], eax

jg .L3

mov eax, DWORD PTR [rbp-12]

cdq

idiv DWORD PTR [rbp-4]

mov eax, edx

test eax, eax

jne .L4

mov DWORD PTR [rbp-8], 1

jmp .L3

.L4:

add DWORD PTR [rbp-4], 1

jmp .L5

.L3:

cmp DWORD PTR [rbp-8], 0

jne .L6

mov eax, DWORD PTR [rbp-12]

mov esi, eax

mov edi, OFFSET FLAT:_ZSt4cout

call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

mov esi, OFFSET FLAT:.LC4

mov rdi, rax

call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

.L6:

mov eax, DWORD PTR [rbp-12]

add eax, 1

mov DWORD PTR [rbp-12], eax

jmp .L7

.L2:

mov eax, 0

leave

ret

__static_initialization_and_destruction_0(int, int):

push rbp

mov rbp, rsp

sub rsp, 16

mov DWORD PTR [rbp-4], edi

mov DWORD PTR [rbp-8], esi

cmp DWORD PTR [rbp-4], 1

jne .L11

cmp DWORD PTR [rbp-8], 65535

jne .L11

mov edi, OFFSET FLAT:_ZStL8__ioinit

call std::ios_base::Init::Init() [complete object constructor]

mov edx, OFFSET FLAT:__dso_handle

mov esi, OFFSET FLAT:_ZStL8__ioinit

mov edi, OFFSET FLAT:_ZNSt8ios_base4InitD1Ev

call __cxa_atexit

.L11:

nop

leave

ret

_GLOBAL__sub_I_main:

push rbp

mov rbp, rsp

mov esi, 65535

mov edi, 1

call __static_initialization_and_destruction_0(int, int)

pop rbp

ret

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote