Skip to contentSkip to conversation

Newbie Question

DISCUSSION dAvId KeDrOsKy 4 participants 4 messages Oct 24, 2002 – Oct 25, 2002

lore
Share & tools
lore
#0 lore raw

Hello,

I have recently started learning x86 assembly and have been programming it in Linux with NASM (Netwide Assembler).

I am trying to write a program that takes a string as input, reverses it and calculated its length. I'm using the stack to do so.

Here's my problem.. NASM only lets me move the string into a 32-bit register.

e.g. mov EBX, the_string ; move memory address of the_string into EBX

At this point I need to push the register on the stack. I know I can do:

push EBX
call string_length_procedure

BUT I was wondering how it is possible to push BX instead. Does BX also hold the string in this case, considering the size of the string it isn't that big? If not, is there a way to put the contents of EBX (the string) into BX? For the time being I would like to just deal with 16-bit registers because it is easier to follow along with the book I am using.

P.s. I am using an already coded procedure that gets the string for me and puts it into 'string' in this case.

#1 lore raw
Quoted 6 lines

BUT I was wondering how it is possible to push BX instead. Does BX also hold the string in this case, considering the size of the string it isn't that big? If not, is there a way to put the contents of EBX (the string) into BX? For the time being I would like to just deal with 16-bit registers because it is easier to follow along with the book I am using.

Yes but if you are using linux it uses 32-bit memory pointers so you should use the 32 bit regs. If you want use some "done" work which is 16bit you can just put "e" in front of 16 bit registers to ensure functionality. (I think)

Regards

Rudolf

#2 lore raw
In reply to dAvId KeDrOsKy
Quoted 2 lines

Here's my problem.. NASM only lets me move the string into a 32-bit register.

Please note that the register does NOT contain the string -- just a POINTER to the string (i.e., its memory address).

Quoted 3 lines

BUT I was wondering how it is possible to push BX instead. Does BX also hold the string in this case, considering the size of the string it isn't that big?

The size of the POINTER has no relationship to the size of the string. (If I give you a street address, like 1148 23rd Ave. S, you have no way of telling from that address if the house is big or small.)

Quoted 4 lines

If not, is there a way to put the contents of EBX (the string) into BX? For the time being I would like to just deal with 16-bit registers because it is easier to follow along with the book I am using.

Then perhaps you need a different book.

Imagine an airplane pilot climbing into the cockpit of a 747 and asking how he can use a propeller instead of a jet engine, because he doesn't need to fly very far, and the flying instructions he was given was for an airplane with a propeller. What odds would you give that that pilot is going to be able to get to the runway, much less off of it?

b

#3 lore raw

Here is a 32 bit i386 assembler course;

http://www.drpaulcarter.com/pcasm/

It has good linux coverage. This link can be found on Konstanin's linux assembly resources page.

Quoted 3 lines · Brian Raiter

Then perhaps you need a different book.

Signature · 3 lines
Robin Miyagi<[email protected]>
http://penguin.c2c2c.ca/
The funny thing about brakes, is that when they break, they don't brake.