[Show all top banners]
Back to: Computer/IT Refresh page to view new replies
 Assembly Language Code Help
[VIEWED 8720 TIMES]
SAVE! for ease of future access.
Posted on 03-23-15 9:38 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Part 1

Implement the following C++ code fragment in assembly language. Use the block-structured .IF and .WHILE directives. Assume that all variables are 32-bit integers.

int array[] = {3,1,4,1,5,9,2,6, 5,3,5,8,9,7,9,3,2,3,8,4};
int lower = 3;
int upper = 8;
int ArraySize = sizeof array / sizeof lower;
int index = 0;
int sum = 0;
while( index < ArraySize )
{
if( array[index] >= lower && array[index] <= upper )
{
sum += array[index];
}
index++;
}

Your assembly language program must also display as output the number of times a member of ' array 'e qualified for inclusion into the ' sum 'e and what the final value of the variable ' sum 'e was. (Hint: you may have to add another variable.) Feel free to use the author's procedures in the book's link library. Use only the procedures that were introduced in chapter 5.
Part 2
Write a program that asks the user to enter an integer dollar amount between 1 and 5,000. Your program should display the corresponding class description using the following table. Write the program so that it executes until the user inputs some value that you determine to be the "stop value". Your program must guard against and provide user messages for input values that are outside the valid range.
Donation Amount (dollars)
Class of Donation
$4,000 to $5,000
Platinum
$3,000 to $3,999
Gold
$2,000 to $2,999
Silver
$1,000 to $1,999
Bronze
$1 to $999
Copper


This is what I have so far. Could someone tell me where is the problem in this code!! It's not working :(

INCLUDE Irvine32.inc

.data
sum DWORD 0
index DWORD 0
array DWORD 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4
lower DWORD 3
upper DWORD 8
ArraySize = ($ - Array) / TYPE array

message1 db "Enter an amount between $1 and $5000 (or enter 0 to quit): ", 0
message2 db "Class of Donation: ", 0
message3 db "Error:Donated amount must be between $1 and $5000!!", 0

.code
main PROC

mov eax, 0
mov edx, lower
mov esi, 0
mov ebx, upper
mov ecx, ArraySize

L1 : cmp esi, ecx
jl L2
jmp L6

L2 : cmp array[esi * 4], edx
jg L3
jmp L5

L3 : cmp array[esi * 4], ebx
jl L4
jmp L5

L4 : add eax, array[esi * 4]

L5 : inc esi
jmp L1

L6 : mov sum, eax
; call ArraySize
; call sum
call DumpRegs

pushad
call Clrscr
mov edx, OFFSET message1
call WriteString
call ReadInt
call Crlf

.IF eax > 5000
mov edx, OFFSET message3
call WriteString
jmp quit
.ENDIF

cmp eax, 0
je quit

.IF eax >= 4000
mov al, "P"

.ELSEIF eax >= 3000
mov al, "G"
.ELSEIF eax >= 2000
mov al, "S"
.ELSEIF eax >= 1000
mov al, "B"
.ELSE
mov al, "C"
.ENDIF

mov edx, OFFSET message2
call WriteString
call WriteChar
call Crlf

Quit :
popad
ret

exit
main ENDP
END main

 
Posted on 03-24-15 9:01 PM     [Snapshot: 103]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

for the first part, here's a disassembly from vs2013 compiler

https://gist.githubusercontent.com/oneminot/5d0a588dd09d4f039eac/raw/de858ad9d73504705add3dff10f892637b59e185/hmm

your code begins with line

009B545E mov dword ptr [array],3
 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 7 days
Recommended Popular Threads Controvertial Threads
I hope all the fake Nepali refugee get deported
and it begins - on Day 1 Trump will begin operations to deport millions of undocumented immigrants
Travel Document for TPS (approved)
All the Qatar ailines from Nepal canceled to USA
MAGA मार्का कुरा पढेर दिमाग नखपाउनुस !
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters