Skip to contentSkip to conversation

Newbie Question

DISCUSSION dAvId KeDrOsKy 6 participants 6 messages Feb 27, 2003 – Feb 28, 2003

lore
Share & tools
lore
#0 lore raw

The following program gives me a seg fault. But I don't understand why.

1. mov ebx, dword 1234
2. mov ax, [ebx]

To me the code would mean 1) move the integer 1234 into ebx and then 2) move the value of ebx into ax. But of course my reasoning is incorrect.

Feedback would be great.

Dave

#1 lore raw
Quoted 7 lines · dAvId KeDrOsKy

The following program gives me a seg fault. But I don't understand why.

1. mov ebx, dword 1234
2. mov ax, [ebx]

To me the code would mean 1) move the integer 1234 into ebx and then 2) move the value of ebx into ax. But of course my reasoning is incorrect.

You are trying to apply indirection to ebx, failing while trying to read from a memory location that is not accessible to your process.

Drop the brackets, and also you probably want eax, right?

Signature · 2 lines
Peace can only come as a natural consequence
of universal enlightenment. -Dr. Nikola Tesla
#2 lore raw
In reply to dAvId KeDrOsKy
Quoted 9 lines

The following program gives me a seg fault. But I don't understand why.

1. mov ebx, dword 1234
2. mov ax, [ebx]

To me the code would mean 1) move the integer 1234 into ebx and then

its OK

2) move the value of ebx into ax. But of course my reasoning is incorrect.

BAD 1) you cant use opernads of different sizes.

on one side must be 32 on another 32 tooo

2) operator [ ] is used for referencing into memory, so you were accessing a memory and thats why the segfault (adress 0x1234 of process is onexistent)

if you want to "shorter" 32 bit value to 16 bit then use

mov eax,0 ;xor eax,eax works too
mov ax,bx ;copy value from BX to AX

Ah dragan you were faster....

Regards

Rudolf

Quoted 9 lines

Feedback would be great.

Dave
-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to dAvId KeDrOsKy
Quoted 7 lines · dAvId KeDrOsKy

The following program gives me a seg fault. But I don't understand why.

1. mov ebx, dword 1234
2. mov ax, [ebx]

To me the code would mean 1) move the integer 1234 into ebx and then 2) move the value of ebx into ax. But of course my reasoning is incorrect.

Assuming that you want the (16-bit) word at address 1234 to be loaded into ax, I see two problems:
a. address 1234 probably cannot be accessed by your program, and b. linux is unhappy if you change ebx. (Your program needs to
save/restore ebx.)

Bob

---------------------------------------------------------------------------------------
Robert G. Plantz, PhD | http://www.cs.sonoma.edu/~bob
Sonoma State University | ph: (707) 664-2806
CS Department | fax: (707) 664-3012
1801 E. Cotati Avenue | email: [email protected]
Rohnert Park, CA 94928

#4 lore raw

Robert G. Plantz am Donnerstag, 27. Februar 2003 23:42:

Quoted 5 lines

Assuming that you want the (16-bit) word at address 1234 to be loaded into ax, I see two problems:
a. address 1234 probably cannot be accessed by your program, and b. linux is unhappy if you change ebx. (Your program needs to
save/restore ebx.)

not linux, but (probably) "C"...
i/o related syscalls use ebx for the file descriptor

hp

Signature · 2 lines
Linux,Assembly,Forth: <http://www.lxhp.in-berlin.de/index-lx.shtml>
    pse, reply to << lxhp -at- lxhp -dot- in-berlin -dot- de >>
#5 lore raw
In reply to dAvId KeDrOsKy
Quoted 10 lines · --- dAvId KeDrOsKy

The following program gives me a seg fault. But I don't understand why.

1. mov ebx, dword 1234
2. mov ax, [ebx]

To me the code would mean 1) move the integer 1234 into ebx and then 2) move
the value of ebx into ax. But of course my reasoning is incorrect.

First of all, if you need to pass an integer to ebx (32 bit register) you may wanna to do
1. mov ebx, 1234
Second, if you put the brackets between a register, its memory address is passed to ax, in this case. Third, you can't move a 32 bit register into a 16 bit one. Use eax, instead.
2. mov eax, ebx
Advice: you can decompose a 32 bit register, ie eax, in ax. Then you can decompose ax in ah and al (8 bit registers).
If hope it will help you.

Quoted 9 lines

Feedback would be great.

Dave
-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in
the body of a message to [email protected] More majordomo info at

http://vger.kernel.org/majordomo-info.html

Regards,

Slack

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/