Old to new assembly, whats wrong ? 
Author Message
 Old to new assembly, whats wrong ?

Hi,

I have been away from assembly for some time, favouring more high level
languages.
I am trying to include this code in borland c 4.5 or Visual C++ 5.0 and
I keep getting errors such 'module does not support 16 bit segments' or
in visual c 'operand does not support 16 bit numbers'.  errors reported
by first few lines and beyond.

All the code does is read in data from the parallel port (on data 0) on
a clock signal on the busy pin and place it in an array.  I am using it
on pentium / II machines but does the processor affect such basic port
calls ?

Any ideas ?

; $Id$
;
; Assembly language to record IR remote control signals. Parts of
; this program are taken from c't 1991, Heft 8 (pp 174 - 178).
;
; Chris Dodge - April 94
;
; Signal from detector read in "Paper Empty".
; Signal from timer read in "Busy".
;
    .MODEL small
    .CODE


    push  bp
    mov   bp, sp
    push  si
    push   ds
    mov     si, [bp+4]   ; Get pointer to array
    mov  cx, [bp+6]      ; Get size of array

; Identify printer port
    push  es              ; Save ES and SI
    push  si

    mov  ax, 40h
    mov  es, ax
    mov  si, 0                 ; Printer port -> SI (lpt1 = 0)
    shl  si, 1
    mov  dx, es:[si+8]         ; Port address -> DX
    inc  dx                  ; Port status reg is 1 byte higher

    pop  si          ; Pull ES and SI back
    pop  es
    mov  bx, 0                 ; Set counter to 0

    call  get_sequence

exit:  sti              ; Allow interrupts again
    mov       ax, bx

    pop  ds
    pop  si
    pop  bp

get_sequence PROC NEAR

    cli                           ; Disable interrupts

S1:        mov  bx, 0                 ; Reset pointer

L1:     ; Start loop - wait until first IR impulse. A trigger is used
    ; here; count the 120 "low" measurements. Noise signals
    ; are usually shorter than this.

    in  al, dx
    and  al, 00100000b         ; Test to see if PE set low
    cmp  al, 0                 ;      (the GP1U52X holds high)
    jne  L1                    ; If high, then reset trigger counter
    mov  al, 00000001b
    mov  [si][bx], al      ; Write a "1" in the buffer
    inc  bx                    ; Incriment buffer pointer

L2:     ; Wait loop until BUSY is low, ie. can then take next input
    in  al, dx                ; Read value into AL
    mov  ah, al                ; Make backup in AH
    and  al, 10000000b     ; Mask the BUSY bit...
    cmp  al, 10000000b     ; ... and check if set
    je  L2

    mov  al, ah        ; If BUSY bit not set, check PE
    and  al, 00100000b     ; Mask PE ....
    cmp  al, 0         ; ...and then write "1" or "0"
    je  P2          ; in buffer

P1:    cmp  bx, 90                ; Have we counter 120 0's yet? If
    jle  S1                    ; not, then noise so start again.
    mov  al, 00000001b     ; Put a '1' in AL
    jmp  P3

P2:    mov  al, 00000000b     ; Put a '0' in AL
    jmp  P3

P3:    mov  [si][bx], al     ; Put the 1 or 0 in signal array
    inc  bx          ; Incriment array pointer

S2:   ; Loop until trigger is set to 0 again (BUSY low)
    in  al, dx
    mov  ah, al
    and  al, 10000000b
    cmp  al, 10000000b
    jne  S2

P4:   ; Main loop - count until the signal array is full
    cmp  bx, cx
    jle  L2

    ret
get_sequence ENDP
    END



Mon, 19 Aug 2002 03:00:00 GMT  
 Old to new assembly, whats wrong ?

Quote:
>I am trying to include this code in borland c 4.5 or Visual C++ 5.0 and
>I keep getting errors such 'module does not support 16 bit segments' or
>in visual c 'operand does not support 16 bit numbers'.  errors reported
>by first few lines and beyond.

<snip>

These compilers are designed for a windows environment. Your code
is not.
Two main problems:
 - The memory model(s) is/are different.
 - A normal Windows program is not allowed to access hardware
 directly using I/O instructions, you have to use Win32 functions.

Two solutions:
 - Use an older (DOS) compiler, and hope that the DOS emulation
 on the target machines are good enough to emulate your port access.
 - Rewrite your module from scratch...

H



Tue, 20 Aug 2002 03:00:00 GMT  
 Old to new assembly, whats wrong ?

Quote:
>I am trying to include this code in borland c 4.5 or Visual C++ 5.0 and
>I keep getting errors such 'module does not support 16 bit segments' or
>in visual c 'operand does not support 16 bit numbers'.  errors reported
>by first few lines and beyond.

Because this languages are pure 32 bit!

Quote:
>    .MODEL small

Due to the pure 32 bit coding, there is only one memory model: flat ! It
provides independent CS and DS segments up to 4 GByte (or just a part of it
~ if you don't like swapping).

Quote:
>    mov   bp, sp
>    push  si

For 32-bit code, these must be EBP, ESP and ESI


Tue, 20 Aug 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. whats new? its NEW

2. whats wrong with smalltalk/x ?

3. Whats wrong with ytalk?

4. Whats wrong with this?

5. Whats wrong with this?

6. Whats wrong with this Picture

7. Whats wrong with this picture

8. Help find whats wrong with this DBF

9. Monad in Haskell - whats wrong with this ?

10. whats wrong with this group...

11. Whats wrong

12. define-inline: Whats wrong with this macro

 

 
Powered by phpBB® Forum Software