10

What is the difference between bx and bp in assembly? Example here:

mov bx, 1h
mov bp, 1h

Do they reference to the same memory? Is it the same with ss and sp?

djot
  • 2,952
  • 4
  • 19
  • 28
tina nyaa
  • 991
  • 4
  • 13
  • 25

2 Answers2

21

In x86 the registers bx and bp are totally unrelated. The only common thing about them is the word base.

  • bx (base index) is a general-purpose register (like ax, cx and dx), typically used as a pointer to data (used for arrays and such)
  • bp (base pointer) is typically used to point at some place in the stack (for instance holding the address of the current stack frames)

Again, ss and sp are different as well.

  • ss (stack segment) is a segment register (like cs, ds and es). It holds the segment used by the stack.
  • sp (stack pointer) points at the top of the stack
cnicutar
  • 178,505
  • 25
  • 365
  • 392
  • If stack is empty, do `ss` point to same place as `sp` and thank you!? – tina nyaa Sep 02 '11 at 05:03
  • @tina nyaa Like I said, `ss` and `sp` are totally unrelated (you need to follow that link on x86 segmentation). There is a relationship between `sp` and `bp`. – cnicutar Sep 02 '11 at 05:04
  • additionally the behaviour in 16 bit is a little different. [BX] uses segment DS so it points to the address DS:BX while [BP] uses segment SS, so it points to SS:BP. – PA. Sep 14 '11 at 09:14
  • and you need to understand segment addressing. SS:SP points to the current top of the stack. Take SS shift it 4 bits to the left and add SP and voila you got the 20 bit linear address. See http://en.wikipedia.org/wiki/X86_memory_segmentation for more information – PA. Sep 14 '11 at 09:18
0

BP register mainly helps in referencing the parameter variables passed to a subroutine. The address in SS register is combined with the offset in BP to get the location of the parameter. BP can also be combined with DI and SI as base register for special addressing.

BX: used in index and indirect addressing