Re: [nasm-devel] regarding problem when i use NASM to run a executable

From: Frank Kotler (fbkotler_at_comcast.net)
Date: 09/29/04


Date: Wed, 29 Sep 2004 07:57:01 GMT

Frank Kotler wrote:
>
> bharat kumar wrote:
> > > i have written a peice of asm code to check the PE (protected
> >
> > > mode)bit in CR0.
> > > when i compile it and link it using nasm for linux ,i am getting the
> > > the executable file.
> >
> > > but when i run the .out file i am getting segmentation fault.so ,what
> > > should i do .

...
> ... smsw may do what you want(?).
...

Hmmm, interesting... According to the Nasm manual, smsw should store
only the low half of cr0, even if given a 32-bit destination. The
results I'm getting (AMD K6) look like I'm getting *all* of cr0. Maybe
there's a glitch in my code(?). Maybe it's an error in the doc(?).
Comments?

Best,
Frank

P.S. cc'ing this to the Yahoo linux-nasm-users list, and the SourceForge
nasm-users list, as the Yahoo nasm-devel list is more or less "dead".
Guess I'll cc it to alt.lang.asm, too - they need some "signal" :)

;-----------------------
; tests smsw instruction
;
; nasm -f elf myprog.asm
; ld -o myprog myprog.o
;-----------------------

global _start

section .text
_start:

    smsw eax
    call eax2bin

    mov al, 10
    call putc
.exit:
    xor ebx, ebx
    mov eax, 1
    int 80h
;-----------------

;-----------------
; print eax as binary
;-----------------
eax2bin:
    push eax
    push ebx
    push ecx

    mov ecx, 32
    mov ebx, eax
.top:
    test ecx, 3
    jnz .skip
    cmp ecx, byte 32
    jz .skip
    mov al, '_'
    call putc
.skip:
    xor eax, eax
    rol ebx, 1
    adc al, '0'
    call putc
    dec ecx
    jnz .top

    pop ecx
    pop ebx
    pop eax
    ret
;----------------------------

;-----------------------------
; print character in al
;-----------------------------
putc:
    push edx
    push ecx
    push ebx
    push eax

    mov ecx, esp
    mov edx, 1
    mov ebx, 1
    mov eax, 4
    int 80h

    pop eax
    pop ebx
    pop ecx
    pop edx
    ret
;-----------------------



Relevant Pages