Prefetch Input Queue - Example Program To Detect Size

Example Program To Detect Size

This is an example NASM-syntax self-modifying x86-assembly language algorithm that determines the size of the PIQ:

code_starts_here: xor cx, cx ; zero register cx xor ax, ax ; zero register ax mov dx, cs mov, dx ; "calculate" codeseg in the far jump below (edx here too) around: cmp ax, 1 ; check if ax has been alterd je found_size mov, 0x90 ; 0x90 = opcode "nop" (NO oPeration) inc cx db 0xEA ; 0xEA = opcode "far jump" dw flush_queue ; should be followed by offset (rm = "dw", pm = "dd") code_segment: dw 0 ; and then the code segment (calculated above) flush_queue: mov, 0x40 ; 0x40 = opcode "inc ax" (INCrease ax) nop_field: nop times 256 jmp around found_size: ; ; register cx now contains the size of the PIQ ; this code is for real mode and 16-bit protected mode, but it could easily be changed into ; running for 32-bit protected mode as well. just change the "dw" for ; the offset to "dd". you need also change dx to edx at the top as ; well. (dw and dx = 16 bit addressing, dd and edx = 32 bit addressing) ;

What this code does is basically that it changes the execution flow, and determines by brute force how large the PIQ is. "How far away do I have to change the code in front of me for it to affect me?" If it is too near (it is already in the PIQ) the update will not have any effect. If it is far enough, the change of the code will affect the program and the program has then found the size of the processor's PIQ. If this code is being executed under multitasking OS, the context switch may lead to the wrong value.

Read more about this topic:  Prefetch Input Queue

Famous quotes containing the words program, detect and/or size:

    If we should swap a good library for a second-rate stump speech and not ask for boot, it would be thoroughly in tune with our hearts. For deep within each of us lies politics. It is our football, baseball, and tennis rolled into one. We enjoy it; we will hitch up and drive for miles in order to hear and applaud the vitriolic phrases of a candidate we have already reckoned we’ll vote against.
    —Federal Writers’ Project Of The Wor, U.S. public relief program (1935-1943)

    If the individuals who compose the purest circles of aristocracy in Europe, the guarded blood of centuries, should pass in review, in such manner as that we could, at leisure, and critically inspect their behavior, we might find no gentleman, and no lady; for, although excellent specimens of courtesy and high-breeding would gratify us in the assemblage, in the particulars, we should detect offence. Because, elegance comes of no breeding, but of birth.
    Ralph Waldo Emerson (1803–1882)

    Crotchless trouser allows wearer to show private parts in public. Neoprene-coated nylon pack cloth is stain resistant, water repellent and tickles thighs when walking. Tan-olive shade goes with most fetishes. Adjustable straps attach to belt for good fit and easy up-down. Pant is suitable for fast exposures as well as extended engagements. One size fits all.
    Alfred Gingold, U.S. humorist. Items From Our Catalogue, “Flasher’s Pants,” Avon Books (1982)