Jump to content

need help fixing this

- - - - -

  • Please log in to reply
5 replies to this topic

#1
club24

club24

    Newbie

  • Members
  • Pip
  • 4 posts
I made a program where I compare 4 digits of 16 bits and store the largest value into ax and the smallest to dx. The problem is NASM won't let me compile the codes because using ax or dx gives me a "format does not support non-32-bit relocation" error. I searched in google and apparently there's a specific linker for 16 bit. I tried ALINK and it wouldn't work. So does anyone have an idea?

part of my program looks smtg like this:

        mov	bx,var1	;move var1 into register bx

	cmp	bx, var2	;compare var1 against var2

	jg	next		;if var1 is greater, jump to next

	mov	bx, var2	;move value of var2 to register bx

	jl	next		;if var is greater, jump to next


Edited by dargueta, 04 April 2011 - 12:37 AM.


#2
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
One of the things, are you using any preprocessor statements, such as BITS, ORG, USE16, USE32, ... ?

The other thing, what, exactly, is that piece of code meant to do and on which of those lines does the error occur?

#3
club24

club24

    Newbie

  • Members
  • Pip
  • 4 posts
I tried using BITS 16, but they wouldn't let me use it when I was trying to change .asm to .o

They gave me 4 int digits 16 bits and I'm suppose to compare them. I need to store largest in ax register and smallest in dx register. The problem is NASM wouldn't let me use these registers claiming "format does not support non 32 bit relocations". So any code that has "ax" "bx" or "dx" causes an error. For example:


mov	bx,var1	    ;move var1 into register bx            [B]causes that error[/B]

cmp	bx, var2	    ;compare var1 against var2           [B]causes that error[/B]

jg	next	            ;if var1 is greater, jump to next

mov	bx, var2    	    ;move value of var2 to register bx   [B]causes that error[/B]

jl	next	            ;if var is greater, jump to next


Edited by dargueta, 04 April 2011 - 12:37 AM.


#4
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
I am not too sure, I mean "p.asm" assembles fine on my computer.

"p.asm":

start: 


mov bx,[var1] 

cmp bx, [var2] 

jg next 

mov bx, [var2] 

jl next 




next: 




section .bss 

var1                    resd 1 

var2                    resd 1 

I used "... resd 1", which makes the variables 32-bit in size, but that part doesn't matter that much.

I, personally, would have used ax instead of bx, but I don't think that's the problem.

You are missing the square brackets around memory accesses, but I don't think comparing the offset of the variables would cause such an error either.

#5
club24

club24

    Newbie

  • Members
  • Pip
  • 4 posts
I'll send you my full codes in pm then. Maybe I'm assembling it wrong but just in case I did a noob mistake. I want to make sure I know my mistakes at least.

#6
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Your problem is that MASM does this:

mov     eax, blah           ; EAX = contents of blah

mov     eax, offset blah    ; EAX = address of blah


And*NASM does this:

mov     eax, [blah]     ; EAX = contents of blah

mov     eax, blah       ; EAX = address of blah


Fix your code as necessary.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users