_Retargetable Concurrent Small C_
by Andy Yuen

Example 1:

(a) 
macroname(arg1, arg2,..., argn)

(b)
define(`OPxy',
`MOV A,$3
ifelse(len($5), 0, `$1 A', `$1 A,$5')
MOV $3,A
MOV A,$4
ifelse(len($6), 0, `$1 A', `$2 A,$6')
MOV $4,A')

Example 2:

(a)
OPxy(ADD, ADDC, R3, R2, R5, R4)

(b)
MOV A,R3
ADD A,R5
MOV R3,A
MOV A,R2
ADDC    A,R4
MOV R2,A

Example 3:

__intr_1:
LCALL   __handler       ;;common interrupt handler
DW      __dodelta       ;;user interrupt function
DW      1               ;;interrupt number

Example 4: (a) 80x86 version; (b) 8051 version



(a)
vargfunc(argc) int argc; {
    int *nxtarg;
    int *ptr, *ctl;

    /* get pointer to first argument */
    nxtarg = CCARGC() + &argc - 1;
    ...
    /* get first argument */
    ptr = *nxtarg--;
    ...
    /* get next argument */
    ctl = *nxtarg--;
    ...
}

(b)
vargfunc(argc) int argc; {
    int *nxtarg;
    int *ptr, *ctl;

    /* get pointer to first argument */
    nxtarg = &argc - CCARGC() + 1;
    ...
    /* get first argument */
    ptr = *nxtarg++;
    ...
    /* get next argument */
    ctl = *nxtarg++;
    ...
}

Example 5: 

(a)
vargfunc(argc) int argc; {
    va_list nxtarg;
    int *ptr, *ctl;

    /* get pointer to first argument */
    va_start(nxtarg, argc);
    ...
    /* get first argument */
    ptr = va_arg(nxtarg, int);
    ...
    /* get next argument */
    ctl = va_arg(nxtarg, int);
    ...
}


Listing One
/*  ** copy t to s  */
strcpy(s, t) char *s, *t; {

  char *d;
  d = s;
  while (*s++ = *t++) ;
  return (d);
  }

Listing Two
TOSEG(2)
CSCEXTRN
ENDSEG(2)
TOSEG(1)
ENDSEG(1)
TOSEG(2)
DECLPUBLIC(_strcpy, 2)
ENTER
ADDSP(-2)
GETw1s(6)
POINT2s(-2)
PUTwp1
LABm(_2:)
POINT2s(6)
GETw1p(0)
INCwp
PUSH1
POINT2s(4)
GETw1p(0)
INCwp
MOVE21
GETb1p(0)
POP2
PUTbp1
NE10f(_3)
JMPm(_2)
LABm(_3:)
GETw1s(-2)
RETURN(2)
ENDSEG(2)
END

Listing Three
CODE SEGMENT PUBLIC
ASSUME CS:CODE, SS:DATA, DS:DATA
extrn __eq: near
extrn __ne: near
extrn __le: near
extrn __lt: near
extrn __ge: near
extrn __gt: near
extrn __ule: near
extrn __ult: near
extrn __uge: near
extrn __ugt: near
extrn __lneg: near
extrn __switch: near
CODE ENDS

 DATA SEGMENT PUBLIC
DATA ENDS
 CODE SEGMENT PUBLIC
ASSUME CS:CODE, SS:DATA, DS:DATA
PUBLIC _strcpy
_strcpy:
PUSH BP
MOV BP,SP
ADD SP,-2
MOV AX,6[BP]
LEA BX,-2[BP]
MOV [BX],AX
_2:
LEA BX,6[BP]
MOV AX,[BX]
INC WORD PTR [BX]
PUSH AX
LEA BX,4[BP]
MOV AX,[BX]
INC WORD PTR [BX]
MOV BX,AX
MOV AL,[BX]
CBW
POP BX
MOV [BX],AL
OR AX,AX
JNE $+5
JMP _3
JMP _2
_3:
MOV AX,-2[BP]
MOV SP,BP
POP BP
RET
CODE ENDS
END

Listing Four
SEG CODE 
include "runtime.i"

SEG XDATA AT MNAME_var_at 
SEG CODE 

PUBLIC _strcpy:

;;ENTER
POP B
POP ACC
LCALL __enter

;;ADDSP(-2)

MOV DPTR,# 2
LCALL __addsp

;;GETw1s(6)
MOV DPTR,# -3
LCALL __getw1s
;;POINT2s(-2)
MOV DPTR,# 5
LCALL __point2s
;;PUTwp1
MOV DPL,R5
MOV DPH,R4
MOV A,R2
MOVX @DPTR,A
INC DPTR
MOV A,R3
MOVX @DPTR,A

_2:
;;POINT2s(6)
MOV DPTR,# -3
LCALL __point2s
;;GETw1p(0)
MOV DPTR,# 0
LCALL __getw1p
;;INCwp
MOV DPL,R5
MOV DPH,R4
INC DPTR
MOVX A,@DPTR
ADD A,#1
MOVX @DPTR,A
MOV DPL,R5
MOV DPH,R4
MOVX A,@DPTR
ADDC A,#0
MOVX @DPTR,A
;;PUSH1
LCALL __push1
;;POINT2s(4)
MOV DPTR,# -1
LCALL __point2s
;;GETw1p(0)
MOV DPTR,# 0
LCALL __getw1p
;;INCwp
MOV DPL,R5
MOV DPH,R4
INC DPTR
MOVX A,@DPTR
ADD A,#1
MOVX @DPTR,A
MOV DPL,R5
MOV DPH,R4
MOVX A,@DPTR
ADDC A,#0
MOVX @DPTR,A
;;MOVE21

MOV A,R3
MOV R5,A
MOV A,R2
MOV R4,A
;;GETb1p(0)
MOV DPTR,# 0
LCALL __getb1p
;;POP2
LCALL __pop2
;;PUTbp1
MOV DPL,R5
MOV DPH,R4
MOV A,R3
MOVX @DPTR,A
;;NE10f
MOV A,R3
ORL A,R2
JNZ $+5
LJMP _3
;;JMPm(_2)
LJMP _2

_3:
;;GETw1s(-2)
MOV DPTR,# 5
LCALL __getw1s
;;RETURN(2) 
MOV DPTR,# -2-4
LJMP __return

END




