NASM - The Netwide Assembler

NASM Forum => Using NASM => Topic started by: Steven S on December 04, 2008, 04:40:45 AM

Title: resb operation size unspecified
Post by: Steven S on December 04, 2008, 04:40:45 AM
I'm working on a project to multiply 2 128 bit numbers, and print the result from a 256 bit number.  Basically the idea is to get two binary numbers  'x' and

'y', and add 'x' to 'product' every time a bit is 1 in 'y'.  After every bit in 'y' I check, I shift 'y' and 'product' one bit to the left.  


This is my first attempt at writing Assembly code, and I'm having some trouble with the resb variables.

How do you initialize a variable created via resb?  (or maybe I'm misunderstanding the purpose of resb?)

How can you use the BT or add functions upon these resb variables?  (again, if possible)


section .data
        counter1 dd 0
        counter2 dd 128
section .bss
        number1 resb 16
        number2 resb 16
        product resb 32
        constantAdd resb 16
section .text
        globalstart:

start:
        mov [constantAdd], 0
        BTC constantAdd, 127
        mov [counter1], 0
        mov [counter2], 0
        mov [number1], 0
        mov [number2], 0
        mov [product], 0
        mov [constantAdd], 0

I am currently receiving  these errors for this portion of the code:
second.asm:13: error: operation size not specified
second.asm:14: error: invalid combination of opcode and operands
second.asm:15: error: operation size not specified
second.asm:16: error: operation size not specified
second.asm:17: error: operation size not specified
second.asm:18: error: operation size not specified
second.asm:19: error: operation size not specified
second.asm:20: error: operation size not specified

Any help as to how I can fix these errors and better use resb variables) is much appreciated.
Title: Re: resb operation size unspecified
Post by: Steven S on December 04, 2008, 05:04:45 AM
use dword[variable]  and it fixes the size specification problems
Title: Re: resb operation size unspecified
Post by: nobody on December 04, 2008, 02:06:46 PM
Yeah, it shuts Nasm up, but doesn't initialize a 128- or 256-bit variable! You're going to have to do something like:

mov [number1], dword 0
mov [number1 + 4], dword 0
mov [number1 + 8], dword 0
mov [number1 + 12], dword 0

("mov dword [number1], 0" is also acceptable)

At this point, you probably want to do:

xor eax, eax ; a convenient zero - of known size
mov [number1], eax
mov [number1 + 4], eax
...

Just one dword will initialize your counters, of course. "resb" has some "cousins"... resw, resd, resq, reso, and resy. There's also "rest" (I like that one) - ten bytes, 80 bits - but that one probably won't help you.

http://www.nasm.us/doc/nasmdoc3.html#section-3.2.2 (http://www.nasm.us/doc/nasmdoc3.html#section-3.2.2)

You seem to have the right idea how to use 'em.

Now btc... you'll definitely want square brackets around the memory operand...

btc [constantAdd], 127

That "ought" to work, as I understand the manual (though the immediate would be taken mod 32), but Nasm yells at me about it.

btc [constantAdd], eax

assembles, and is more likely to work on the 127th bit (as I understand it). I kinda doubt if btc is what you want...

There *may* be MMX/XMM/SSEn registers/instructions that will help you with this, but I don't know 'em.

Best,
Frank