On Assembly Language [Re: [ros-general] New to ReactOS]

jwalsh at bigpond.net.au jwalsh at bigpond.net.au
Tue Oct 18 06:56:30 UTC 2005


In retrospect there is one important area for the Assembly Language Programmer.
It would only be interesting to the serious enthusiast.
It is writing primitives for very tight Smalltalk.
It is the area of embedded systems. 
Owing to a buggys Windows98se I cannot send attachments (indirectly a good thing).
An Example is below.

Regards and rosuccess

---- Redefined Horizons <redefined.horizons at gmail.com> wrote: 
> Wow! Great news!
>  Now let me ask about volunteering to help with the project. I'd like to get
> some experience programming in assembly language and/or machine code.
>  Is there any need for this on the ReactOS project? Can I start on some
> simple assembly language programming tasks for ReactOS and have someone that
> can guide me through the tough spots?
>  Let me know if I can help in this area.
>  Scott
> 
>  On 10/17/05, KJKHyperion <hackbunny at reactos.com> wrote:
> >
> > Redefined Horizons wrote:
> >
> > > [1] Is ReactOS built on a Unix core, or is it a new operating
> > > sytem from the ground up?
> >
> > ReactOS is all-original, written from the ground up as a clone of the
> > Windows design
> >
> > > [2] Can you dual boot with ReactOS and a Linux operating system like
> > > Debian? If you can, is there a place where I can find instructions on
> > > how to do so?
> >
> > yes, see
> > <http://www.reactos.org/wiki/index.php/HOWTO/boot_FreeLoader_from_GRUB>
> >
> > > [3] Does an application that runs on Microsoft Windows have to be
> > > ported before it can be run on ReactOS?
> >
> > No
> >
> > > Can I try installing the program to see how it works?
> >
> > Yes
> > _______________________________________________
> > ros-general mailing list
> > ros-general at reactos.org
> > http://www.reactos.org/mailman/listinfo/ros-general
> >
-------------------------------------------------------------------------------
PAGE 85,132
TITLE User Defined Primitive #92 (INT 62H)

;      This is an example of a possible user defined primitive.
;      The primitive below "primitive92" is an implementation
;      of the String at: primitive.
;
;      The first part of the code "installs" the primitive 
;      "segment and offset" address into INT 62H vector.
;      The second part, "primitive92" defines the code that
;      will be executed when primitive number 92 from 
;      "Smalltalk/V" is invoked.



PAGE
            INCLUDE fixdptrs.usr
IF1
            INCLUDE access.usr
ENDIF



PAGE
code        SEGMENT 
            ASSUME CS:code,DS:code,ES:code
            ORG 100H

start:      JMP    installPrim



PAGE
primitive92 PROC   FAR

; This is code that will be executed everytime primitive 
; number 92 is invoked from "Smalltalk/V"

            enterPrimitive                  ;enter primitive macro (see macro
                                            ;listings)

            MOV    CX,DI                    ;copy receiver in CX

   ;        getClass DI,DX,ES               ;put class of receiver in DX
   ;
   ;        CMP    DX,ClassStringPtr        ;if class of receiver is not
   ;        JNE    failure                  ;String then primitive fails
   ;                                        ;(This check is commnet since it is
   ;                                        ;not necessary but it is shown here
   ;                                        ;as an example on how to use the
   ;                                        ;getClass macro

            MOV    DI,[BP+16]               ;put index argument in DI

            SHR    DI,1                     ;shift right and 
            MOV    AX,DI                    ;copy in AX
            JNC    smallInt                 ;if no carry (even number) then
            RCL    DI,1                     ;its a small integer and jump else
                                            ;restore the index object ptr

            MOV    DX,SS                    ;set ES to address classes segment
            SHR    DX,1 
            MOV    ES,DX

            CMP    WORD PTR ES:[DI],ClassLargePosInt ;if class of index object
            JNE    failure                  ;pointer is LargePositiveInteger
                                            ;then continue else primitive fails

            getObjectAddress DI,BX,ES       ;get address of index object ptr

            CMP    WORD PTR ES:[BX],4       ;size of this large positive
            JNE    failure                  ;integer must be 4 (2 bytes for
                                            ;size header + 2 bytes for the 
                                            ;number itself) - not 4 suggests
                                            ;that number is more than 2 bytes
                                            ;long and primitive fails else

            MOV    AX,ES:[BX+2]             ;move 2 byte integer into AX and
            JMP    haveIndex                ;jump to haveIndex

smallInt:   JLE    failure                  ;if after shift sign of integer
                                            ;changes or its zero then
                                            ;primitive fails (index must be
                                            ;greater than zero)

haveIndex:  INC    AX                       ;index +1 to correct byte access
            JZ     failure                  ;later on; if value goes to 0 then
                                            ;index was too large and primitive
                                            ;fails


            MOV    BX,CX                    ;set BX to receiver object ptr and
            getObjectAddress BX,DI,ES       ;get address of receiver (string)

            isSizeEven BX,CX,DS             ;check even/odd length of string
                                            ;object (JZ for even length)

            MOV    BX,ES:[DI]               ;move size of string to BX

            JZ     even                     ;if isSizeEven result is zero
            DEC    BX                       ;condition flag then length 
                                            ;of string is even (BX - 2 bytes
                                            ;for size header) else length of 
                                            ;string is odd (BX - 3) so adjust
                                            ;size of string (BX) by -1

even:       CMP    AX,BX                    ;adjusted index must be less than
            JAE    failure                  ;BX (string size) else primitive
                                            ;fails

                                            ;now we must get the character
                                            ;from the string and turn it into
                                            ;an object pointer 
            XOR    CH,CH                    ;set CH to zero
            MOV    BX,AX                    ;set BX to be adjusted index
            MOV    CL,ES:[DI+BX]            ;move to CL the char from string
            SHL    CX,1                     ;multiply CX by 2
            ADD    CX,FirstCharacterPtr     ;add to CX the base character ptr

            MOV    BX,CX                    ;set BX to result char pointer
            exitWithSuccess 1               ;and enter into successful exit
                                            ;macro with arg count 1 (the index)

failure:    exitWithFailure 1               ;failure macro with arg count 1

primitive92 ENDP

primitive92end LABEL BYTE                   ;label for exit and stay resident

; This is primitive "installation code" with the exit and 
; stay resident

installPrim PROC   NEAR
            MOV    AX,CS                    ;set DS to address code segment
            MOV    DS,AX
            MOV    DX,OFFSET primitive92    ;load DX with primitive offset
            MOV    AX,2562H                 ;use DOS to set address of INT 62H
            INT    21H
            LEA    DX,primitive92end        ;load DX with address beyond last
            INT    27H                      ;byte - exit and stay resident
installPrim ENDP
SUBTTL
PAGE
code        ENDS
            END start






More information about the Ros-general mailing list