Author Topic: declaring a constant - help  (Read 5461 times)

Offline jalisco

  • Jr. Member
  • *
  • Posts: 6
declaring a constant - help
« on: July 10, 2013, 07:19:32 AM »

The attached code functions - almost.

It basically, computes a floating point number up to 30 digits.

The problem is in line 225. If I use 30 here, it calculates perfectly, up to 30 digits, like I want.

My more specific problem is setting up a constant, in the code, so I can easily change it later, without having to fish through the code (and find line 225 again) to change the 30, to some other number.

I have tried the following:
precision: equ 30
%define precision 30
precision db 30

and used [precision], byte[precision] in place of 30 in line 225.

etc etc..I tried a few other things, but I can't get precision to work...=/

It should be simply?

p.s. Avcabarello, if you do get a chance to look at the source code in the attachment, can you try to debug it? I don't think it works. I will check the link you posted in in another note in a second.
« Last Edit: July 10, 2013, 07:33:39 AM by jalisco »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: declaring a constant - help
« Reply #1 on: July 10, 2013, 03:23:58 PM »
I'd go with:
Code: [Select]
precision equ 30
; and later...
mov cx, precision
"%define precision 30" should also work, and do about the same thing (it's just a text substitution, not a true "constant"). If you're going to make it a variable, "db" would be incorrect. I see you've got it as "dw" in your code, which should also work, but as:
Code: [Select]
mov cx, [precision]
Nasm knows how big cx is, so saying "byte" isn't going to work. You could say "word", but you don't need to. If you really really wanted to make it "db",
Code: [Select]
movzx cx, byte [precision]
... but there's no advantage to it. If you might want to let the user select the precision at run-time, a variable would be the way to do it. If you can decide the precision at assemble-time, I'd go with "equ".

I haven't even looked at your code, aside from this one issue. What kind of problem have you had with it?