LyME-specific Functions - Machine Code

This chapter describes the functions which permit LyME to call arbitrary machine code. This may be useful to access features which are not implemented directly in LyME, such as direct calls to Palm OS functions or support for hardware.

Warning 1: Calling machine code is potentially dangerous. It easily leads to crashes which may need soft or hard resets. You should backup your device first. The use of an emulator, if available, should be considered.

Warning 2: Presenting Palm device hardware and software architecture is far beyond the scope of this reference manual.

Warning 3: Functions described in this chapter are experimental and subject to change without notice.

Introduction

To support calls to machine code, a new data type is provided, binarydata. Variables of this type contain a vector of 16-bit words. Functions are provided to convert a string of hexadecimal digits or a vector of numbers to binarydata, binarydata to a vector of 16-bit numbers or a string of bytes, and to execute as a machine-code subroutine the content of binarydata using another binarydata as data.

As an example, we will develop a subroutine which fills some binarydata with the numbers n, n-1, ..., 2, 1. Before the subroutine is executed, the following registers are set:

RegisterValue
A5Beginning of the data
D0Length of the data in words

Here is the code of the subroutine:

	moveq.w #0, d1
loop:
	tst.w   d0
	beq     end
	move.w  d0, (a5,d1)
	subq.w  #1, d0
	addq.w  #2, d1
	bra     loop
end:
	rts

The data offset of the next word to set is stored in D1. As long as D0 is not 0, D0 is stored in the data at offset D1 and decremented, and D1 is incremented by 2. The subroutine ends with rts. Note that absolute addresses must be avoided; only relative jumps must be used.

An assembler converts this assembly code to the following machine code:

72004A40670A3B8010005340544160F24E75

To store this code in a binarydata variable, we enter in LyME

> code = binarydata('72004A40670A3B8010005340544160F24E75');

To execute this code with data initialized to 10 null 16-bit words, we use feval:

> dataout = feval(code, binarydata(zeros(10, 1));

The result can be converted to a vector of numbers and displayed:

> double(dataout)
  10
   9
   8
   7
   6
   5
   4
   3
   2
   1

Functions

binarydata

Create binary code or data.

Syntax

d = binarydata(vec)
d = binarydata('hexa')

Description

binarydata(vec) creates a block of binary data from the elements of double vector vec converted to words (16-bits values).

binarydata(str) creates a block of binary data whose value is given by the string of hexadecimal digits str. The length of str must be a multiple of 4, so that the block has an integer number of words.

See also

double, char, feval

char

Convert binary data to a string of characters.

Syntax

str = char(d)

Description

char(d) converts binary data to a a string of characters. Each character corresponds to one byte.

See also

binarydata, double

double

Convert binary data to a vector of double.

Syntax

vec = double(d)

Description

double(d) converts binary data to a column vector of double numbers.

See also

char, binarydata

feval

Call machine language in binary data.

Syntax

feval(code)
dataout = feval(code, datain)

Description

feval(code) calls code in binary data code with the following instructions:

movea #0, a5
clr.w d0
jsr code

feval(code,data) calls code in binary data code with the following instructions:

lea (data), a5
move.l dataSize, d0
jsr code

The binary data data (possibly modified) is returned. In both cases, the code should be a subroutine and end with rts.

Warning

feval has the potential of crashing LyME if its arguments do not correspond to valid code and data.

See also

binarydata


Copyright 2001, Calerga.

All rights reserved.