Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Building a list to average

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!

[code]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
[/code]

Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    [color=Blue]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':[/color]
    [code]
    mov al, buffer
    mov [ebx+esi], al
    [/code]
    [color=Blue]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:[/color]
    [code]movzx eax, byte ptr [ebx+esi][/code]
  • kazo0kazo0 Posts: 2Member
    Thanks for the help! I don't get the error anymore but when I try and print out my list, nothing is being printed.

    [code]
    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
    [/code]

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

Sign In or Register to comment.