Image Map Image Map
Results 1 to 5 of 5

Thread: How to load memory when BX register wraps around in 8088 CPU?

  1. #1

    Default How to load memory when BX register wraps around in 8088 CPU?

    Hi, I need to code a routine that will load up to 65535 (FFFFh) bytes into memory location pointed by ES:BX. The problem that I'm facing is that I will have to change both ES and BX depending on their values. If ES=0000h and BX=4000h and I want to load FFFFh bytes then I have to modify ES when BX wraps around, but if I only want to load 1000h then I'll be ok if I only increase BX. Is there any addressing mode that will do this for me? or do I have to implement this kind of logic?

    This code only works if BX wont wrap around.

    Code:
    	 mov ax, 0
    	 mov es, ax
    	 mov bx, 04000h
    	 mov cx, 0ffffh
    	 mov al, 055h
    load_mem:
    	 mov es:[bx], al
    	 inc bx
    	 dec cx
    	 jnz load_mem

  2. #2
    Join Date
    Jan 2007
    Location
    Pacific Northwest, USA
    Posts
    35,123
    Blog Entries
    18

    Default

    No, you have to modify the segment register. In you case, set ES to 0400h and BX to 0.

    It gets a little more involved when you want to store 65,535 bytes on a boundary that doesn't start on a paragraph.

    This goes to one of my problems with the 8086 architecture that I complained about in 1980. Manipulating large data structures is painful. On the 68K it's straightforward.

  3. #3

    Default

    Yes. More generically, the rule to keep in mind is that (ES + BX>>4):0000 points to the same address as ES:BX... as long as the last nybble of BX is 0.

    The last time I had to fill some 400K of RAM (*quickly*), in chunks much smaller than 64K, I had my inner loops always assume an offset of 0 and did all arithmetic on the segment register exclusively, outside the loop.

    I also feel compelled to point out that your inner load_mem code is, ahem, non-efficient. But you didn't ask, so I'll assume it's just a placeholder for real code.
    int10h.org :: :: :: blog

  4. #4
    Join Date
    Jan 2007
    Location
    Pacific Northwest, USA
    Posts
    35,123
    Blog Entries
    18

    Default

    When handling large data structures, I find that it's convenient to reduce offsets to <32K; you avoid boundary issues with little additional overhead.

    OP: If you want to fill memory fast, consider "rep stos"--and words are faster than bytes.

  5. #5

    Default

    Hi,

    Are you sure you want to copy FFFFh and not 10000h ?


    Your code, to write to the Address 4000h in 32bit can be simplified like this:
    Code:
    	 mov ax,00400h
    	 mov es, ax
    	 xor di,di
             mov cx,4000h
    	 mov eax, 055555555h
             rep stosd
    But of course, it need to be cut in 2 "rep stosb" if the @ is not aligned to a 16 byte bloc

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •