Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this code in assembly. I cannot get my ouput the way the proffesor wants it. ; Similar to Chapter 4 exercises:

I need help with this code in assembly. I cannot get my ouput the way the proffesor wants it.

; Similar to Chapter 4 exercises: Sum the difference between each element in an array

; Example: dwordarray dword 1,5,6,9

;Program description here:

; 2/1/2018

; Assembly Language

; You need a loop below to make this program work properly. Since we use dword array as

; our variable size then that means you add what to get to the 4?

; Would it be dwarray[esi+4]?

; Subtract array element that has 1 in it from element that has 5 in it. Then

; put it in a register like edx. You get 4. Next repeat that with element that has 5 from 6.

; add that to the register edx and you get 5. Repeat with array that has 6 in it from element that has 9, then add

; that to edx register with 5 and you get 8 as the total. Now put what is in the

; edx register into the eax register and print.

; remember at the bottom of the loop add 4 to the esi register each time

; to get to the next element in the array.

INCLUDE Irvine32.inc

.data

topHeading BYTE "%%%%%%%% Week 4 program for %%%%%%%%",0 ;declaration for print

welHeading BYTE "@@@@@@@@ Welcome to Week 4 Assembly Program!!!!!!!! @@@@@@@@",0

pressKey BYTE "**********Press any key to continue:**********",0

dwarray dword 1,5,6,9

count EQU (LENGTHOF dwarray)

;Students should comment your code also.

.code

main proc

mov edx, OFFSET topHeading ;display top heading

call WriteString

call Crlf ;line break

call Crlf ; line break

mov edx, OFFSET welHeading ;display welheading

call WriteString ;null terminateed string

call Crlf ;line break times 3

call Crlf

call Crlf

mov edx,OFFSET pressKey ;inputs press any key instruction

call WriteString ;null terminateed string

call readchar

call Crlf ;line break

;####### Student start code using the next 4 lines.###########

dec count ; Start by moving count - 1 into the

mov ecx,0 ; ecx register because an array starts at 0.

mov esi,0 ; move 0 into esi register

mov edx,0 ; Use the edx register to sum each difference so move 0 into it.

L2: ; start loop#### remember--- dwarray is 1,4,5,7

; ########Student only needs 4 steps in the loop.#######

mov eax,dwarray[esi+4] ; First you move the array from above into the eax register by using the

sub eax,dwarray[esi-2] ; arrayname followed by [esi+4]. This is the second element in the array.

add edx,eax ; now subtract the first element from the eax register by using subtract arrayname follow by [esi].

; next add what is in the eax register to a register. suggestion use edx.

add [esi],4 ; next add 4 to the pointer called esi

loop L2 ; End loop####

mov eax, edx

call dumpregs

call Crlf

call Crlf

call WriteHex ;displays contents of eax as hexadecimal

call Crlf

call Crlf

call WriteInt ;displays contents of eax as integer

call Crlf

mov edx,OFFSET pressKey ;inputs press any key instruction

call WriteString ;null terminateed string

call readchar

exit

main endp

end main

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions

Question

18. If you have power, then people will dislike and fear you.

Answered: 1 week ago