Getting started in assembly

Moderators: None (Apply to moderate this forum)
Number of threads: 219
Number of posts: 577

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Building a list to average Posted by kazo0 on 11 Mar 2011 at 10:16 AM
Hi all,

I need to read in 10 2-digit numbers from the user and then output the numbers along with the average.

I am able to read in the numbers one by one, the problem is I have no idea how to build a list to hold all of the 10 digits in one spot.

I am still very new and I do not understand a lot of things so everytime I read in from the user, the digit is placed into what I called 'buffer' and I defined this in the .bss section as:

buffer resb 1

after that I am trying to build a list with these numbers so I am trying to do:

mov [list+esi], buffer

where I defined list in .bss as

list resb 10

and I keep getting the error: operation size not specified at the line "mov [list+esi], buffer"

I am really lost as to how to build this list and also the sizes that I am supposed to be specifying and indexing by. Any help would be appreciated.

Thanks!

segment .data
        msg db 'Enter a digit from 10 to 99: #'
        len equ $-msg

segment .bss
        buffer: resb 1
        list: resb 10
segment .text
        global _start
_start:
        mov esi, 0
        mov ecx, 10

read:   mov eax, 4
        mov ebx, 1
        mov edi, ecx
        mov ecx, msg
        mov edx, len
        int 0x80

        mov eax, 3
        mov ebx, 0
        mov ecx, buffer
        int 0x80
        mov [list+esi], buffer  <-- Error
        add edi, 1
        mov ecx, edi
        loop read

        mov eax, 4
        mov ecx, 1
        mov ecx, list
        mov edx, 20
        int 0x80

exit:   mov eax, 1
        int 0x80
Report
Re: Building a list to average Posted by AsmGuru62 on 12 Mar 2011 at 6:44 AM
I think the problem may be in the CPU inability to move memory to another memory in one instruction - you need to use TWO instructions: 1st: move buffer into a register and then move that register into other memory - your list declared with 'resb 10':
mov al, buffer
mov [ebx+esi], al

I assume that 'resb' means REServe Byte. So, all your numbers are bytes. When you need an average - you need to add 10 numbers. This SUM can easily overflow a BYTE (which can hold max value of 255). So, when you adding the numbers you need to use a bigger register, like EAX, but then to load BYTE into EAX you need to use MOVZX instruction, something like this:
movzx eax, byte ptr [ebx+esi]
Report
Re: Building a list to average Posted by kazo0 on 12 Mar 2011 at 3:58 PM
Thanks for the help! I don't get the error anymore but when I try and print out my list, nothing is being printed.

        mov ebp, buffer
        mov [list+esi], ebp
        add esi, 1
        mov ecx, edi
        loop read

        mov eax, 4
        mov ecx, 1
        mov ecx, list
        mov edx, 20
        int 0x80

exit:   mov eax, 1
        int 0x80


I tried just printing out one part of the list such as [list] but nothing is printing out.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.