So I recently started taking this class and i never learned assembly language so writing the program was very difficult. I have this project to do and this is part one.

The instructions are:
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];

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.)

This is the program I wrote.

TITLE Project 2                     (main.asm)

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
index DWORD 0
sum DWORD 0
main PROC
    mov eax, 0  ; sum
    mov edx, lower
    mov esi, 0  ; index
    mov ebx, upper
    mov ecx, ArraySize

L1: cmp esi,ecx 
    jl  L2
    jmp L5

L2: cmp array[esi], edx 
    cmp array[esi], ebx 
    jg  L3
    jmp L4
L3: add eax, array[esi] 

L4: inc esi 
    jmp L1

L5: mov sum,eax

call array
call sum

main ENDP

END main

I was successful in bulding the solution but when i ran it, it either showed nothing or it would go unresponsive. Can someone point out the problems in this code for me? I sent emails to my professor but she hasn't responded to me. Thank you.

Recommended Answers

All 2 Replies

Before proceeding, could you tell us which assembler you are using? Different assemblers, even ones for the same CPU, can have very different syntaces, and the one you are using seems unfamiliar to me. I am guessing it is HLA, but I don't know enough about it to say for certain.

I think I am using MASM in this class. I didn't know there were more than one assemblers but that is the one that is written in the preface of the book.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.