I am new to Assembly. I am learning it. I have a question. I am doing this piece of code which is supposed to ask at the prompt for decimal value values, put them in a register and then display them in a reverse order. For example if we entered 12345 then the display will show them as reversed as 54321 then also show them their sum as = 15.

Below is the code I was working on it is doing everything except for the accumulation of the numbers entered and also it does not display them in reverse order.
Detailed program requirement

The program will allow the user to enter a list of numbers in base 10. The number of values to be entered will be entered by the user when the program starts.

After the user enters the numbers, the program will display the numbers in reverse order in hexadecimal, binary, and decimal, separated by the tab character.

Finally, the sum of the numbers will be shown.


Can Someone help me please?

TITLE Integer Summation Program                 (Addnums.asm)

;This program prompts the user for three Integers,
; stores them in an Array, Calculates the sum of the
; array, and displays the sum

INCLUDE Irvine32.inc

TAB = 9 ; ASCII code for Tab

str1 BYTE "Enter an integer: ",0
str2 BYTE "The sum of the integers is: ",0

;main Program control procedure
;calls: Clrsr, PromptForIntegersValues,
;       ArraySum, DisplaySum
main PROC
    call Clrscr
    mov esi, OFFSET array
    call PromptForIntegerValues
    call ArraySum
    call DisplaySum
main ENDP

PromptForIntegerValues PROC USES ecx edx esi
;Prompts the user for the ten integers, inserts
;them in an array.
;Receives: ESI points to an array of
;          doubleword integers, ECX = array size.
;Returns: nothing
;Calls: ReaInt, WriteString
  mov edx, OFFSET str1         ; "Eter a signed integer"
L1: call WriteString            ; display string
   call ReadInt                ; read integer into EAX
   call Crlf                   ; go to next output line
   mov ,eax               ; store in array
   add esi, TYPE DWORD         ; next integer
   loop L1
PromptForIntegerValues ENDP

ArraySum PROC USES esi ecx
; Calculate the sum of an array of 32-bit integers.
; Receives: ESI points to the array, ECX = number of array elements
; Returns: EAX = sum of the array elements
   mov eax, 0                                         ; Set the sum to zero
L1: add eax,                                    ; add each integer to sum
   add esi, TYPE DWORD                          ; point to next integer
   loop L1                                               ; repeat for array size
ArraySum ENDP

DisplaySum PROC USES edx
; Display the sum on the screen.
; Receives: EAX = the sum
; Returns: nothing
; Calls: WriteString, writeInt
  mov edx, OFFSET str2                      ; "The sum of the ..."
  call WriteString ; display the string of values
  call WriteInt                                     ; display EAX contents in signed decimal
  mov al, TAB ; horizontal tab
  call Crlf

;Display the digits in Hexadecimal
  mov edx, OFFSET str2                      ; "The sum of the digits in HEX ..."
  call WriteHex                                   ; display EAX contents in Hexadecimal
  mov al, TAB ; horizontal tab
  call Crlf

;Display the digits in Hexadecimal
  mov edx, OFFSET str2                      ; "The sum of the digits in BIN..."
  call WriteBin                                    ; display EAX contents in Binary
  mov al, TAB ; horizontal tab
  call Crlf  
;Display the digits in Hexadecimal
  mov edx, OFFSET str2 ; "The sum of the digits in Dec..."
  call WriteDec         ; display EAX contents in unsigned decimal
  mov al, TAB ; horizontal tab
  call Crlf

DisplaySum ENDP
END main

Posted on 2010-04-20 02:48:09 by john_blogger
I'm still somewhat of a newbie with ASM as well, also I'm kind of just eyeballing the code, so take my comments with a grain of salt.

-on your  call WriteInt you have a comment "display EAX contents in signed decimal" - this is called upon return of WriteString though, so if it it's your intention to pass it a value the standard calling convention is to use EAX for passing values to a function

-I can't really find any fault with your code, look up the purpose of the function calls and make sure your passing them the right data i.e. passing WriteHex the string of data on the next line (I get that from crlf above in your listed code)

-One potental good way I suggest is run it through a debugger and watch the values to get a good understanding of what's going on..

"Eter a signed integer" is probably a typo for enter
Posted on 2010-04-23 11:11:14 by Brainiac
Register AX is made of two smaller registers AH and AL. You stored the sum of your inputs in AX.

However, right after you print the sum of your inputs for the first time, you moved to AL the value of 9 (TAB) which overwrote your total value.

I got your code working after commenting out every line that overwrites AL:
   ;mov al, TAB					 ; horizontal tab

Also, i have no idea why are moving the value of 9 (TAB) onto AL.
Posted on 2010-12-18 20:43:02 by banzemanga
This really helped me a lot!:D Thanks!
Posted on 2011-09-12 21:04:00 by ziaweslee