English 中文(简体)
如何在组装中使用LODSB?
原标题:What is required to use LODSB in assembly?

如何用LODSB装载相对地址在我的法典中加以阐明所需的最低限度步骤?

我有以下试验方案,即Im使用PXE到boot。 我用两种方式boot:通过pxelinux.0直接。 如果我直接boot,我的节目就印刷了两个插图。 如果我通过Xelinux.0boot,它只印刷了第一部插图。

为什么?

<>Answer>: 该法典是罚款,最初的数学地址是错误的。 见下文。

工作技术(针对两者):

  • Set the direction flag to increment, cld
  • Set ds to cs
  • Put the address (from start) of string in si
  • Add the starting offset to si

非工作技术(食疗):

  • Calculate a new segment address based on (((cs << 4) + offset) >> 4)
  • Set ds to that. (either A000 or 07C0)

>

// Note: If you try this code, don t forget to set 
//       the "#if 0" below appropriately!

    .text
    .globl  start, _start

start:  
_start: 
_start1:    

    .code16

    jmp real_start

    . = _start1 + 0x1fe
    .byte 0x55, 0xAA

    // Next sector
    . = _start1 + 0x200

    jmp real_start

test1_str:
    .asciz  "
Test: 9020:fe00"
test2_str:
    .asciz  "
Test: a000:0000"

real_start:

    cld         // Make sure %si gets incremented.

#if 0
    // When loaded by pxelinux, we re here:
    // 9020:fe00 ==> a000:0000

    // This works.
    movw    $0x9020, %bx
    movw    %bx, %ds
    movw    $(test1_str - _start1), %si
    addw    $0xfe00, %si
    call    print_message

    // This does not.
    movw    $0xA000, %bx
    movw    %bx, %ds
    movw    $(test2_str - _start1), %si
    call    print_message
#else
    // If we are loaded directly without pxelinux, we re here:
    // 0000:7c00 ==> 07c0:0000

    // This works.
    movw    $0x0000, %bx
    movw    %bx, %ds
    movw    $(test1_str - _start1), %si
    addw    $0x7c00, %si
    call    print_message

    // This does, too.
    movw    $0x07c0, %bx
    movw    %bx, %ds
    movw    $(test2_str - _start1), %si
    call    print_message
#endif

    // Hang the computer
    sti
1:
    jmp 1b


// Prints string DS:SI (modifies AX BX SI)
print_message:
    pushw   %ax
    jmp 2f
3:
    movb    $0x0e, %ah  /* print char in AL */
    int $0x10       /* via TTY mode */
2:  
    lodsb   (%si), %al  /* get token */
    cmpb    $0, %al     /* end of string? */
    jne 3b
    popw    %ax
    ret

.balign 0x200

本文汇编:

/usr/bin/ccache gcc -Os -fno-stack-protector -fno-builtin -nostdinc  -DSUPPORT_SERIAL=1 -DSUPPORT_HERCULES=1 -DSUPPORT_GRAPHICS=1 -DHAVE_CONFIG_H -I. -Wall -ggdb3 -Wmissing-prototypes -Wunused -Wshadow -Wpointer-arith -falign-jumps=1 -falign-loops=1 -falign-functions=1 -Wundef -g -c -o ds_teststart_exec-ds_teststart.o ds_test.S
/usr/bin/ccache gcc  -g   -o ds_teststart.exec -nostdlib -Wl,-N -Wl,-Ttext -Wl,8000 ds_teststart_exec-ds_teststart.o  
objcopy -O binary ds_teststart.exec ds_teststart
最佳回答

www.un.org/Depts/DGACM/index_spanish.htm 第一期:

9020:FE00 ==> 9000:0000 and not A000:0000
I was using some code from grldrstart.S that does that calculation. There s a bug in the grldrstart.S routine. It takes the FE00 offset and shifts it right 4 bits, but it does it without preserving the sign; FE00 is a negative number. So instead of:

shrw   $4, %bx

本来应该

sarw   $4, %bx   // Preserves sign!!

90200 + FE00 = 90200 - 200 = 90000

<>问答:

为了使用LODSB,你必须:

  • set ds properly (and use correct math)
  • set the direction flag correctly, using cld or std for increment and decrement
  • set si to the offset to your source buffer.
  • the effective address read will be (ds << 4) + si
问题回答

a. 设置ds->

推土

人口





相关问题
How can I do a CPU cache flush in x86 Windows?

I am interested in forcing a CPU cache flush in Windows (for benchmarking reasons, I want to emulate starting with no data in CPU cache), preferably a basic C implementation or Win32 call. Is there a ...

What are the names of the new X86_64 processors registers?

Where can I find the names of the new registers for assembly on this architecture? I am referring to registers in X86 like EAX, ESP, EBX, etc. But I d like them in 64bit. I don t think they are the ...

How do I disassemble raw 16-bit x86 machine code?

I d like to disassemble the MBR (first 512 bytes) of a bootable x86 disk that I have. I have copied the MBR to a file using dd if=/dev/my-device of=mbr bs=512 count=1 Any suggestions for a Linux ...

32bit application access to 64bit registry

I have an OS Shell written in 32bit that is replacing the Explorer.exe of a Vista machine. I run a utility which is also written in 32bit, which allows to switch between the Explorer shell and My ...

Left Shift Overflow on 68k/x86?

I heard that the Motorola 68000 and Intel x86 architectures handle overflow from left shifting differently. Specifically the 68k LSL vs. the Intel SAL/SHL assembly instructions. Does anyone know the ...

Translate a FOR to assembler

I need to translate what is commented within the method, to assembler. I have a roughly idea, but can t. Anyone can help me please? Is for an Intel x32 architecture: int secuencia ( int n, ...

热门标签