Incorporating assembly with c, Incorporating c with assembly, Example – Zilog Z80380 User Manual

Page 48

Advertising
background image

Incorporating Assembly with C

C-Compiler Overview

2–14

UM004001-COR1103

INCORPORATING ASSEMBLY WITH C

The Z380- C-Compiler allows the user to incorporate assembly code into their C code.

In the body of a function, use the asm statement. The syntax for the ASM statement is
_asm(“<assembly line>”);.

The contents of <assembly line> must be legal assembly syntax

The only processing done on the <assembly line> is escape sequences

Normal C escape sequences are translated

Example

#include <zilog.h>

int main()

{

_asm(“\tnop\n”);

return (0);

}

INCORPORATING C WITH ASSEMBLY

The C libraries that are provided with the compiler can also be used to add functionality to an
assembly program. The user can create their own function or they can reference the library
using the ref statement.

N

OTE

:

The C-compiler precedes the use of globals with an underscore in the generated assembly.

Example

The following example shows the C function imul() being called from assembly lan-
guage. The assembly routine pushes two words onto the stack (parameters x and y for the
function imul), calls the function imul, then cleans the arguments off the stack.

Assembly file.

.ref _imul; Compiler prepends ‘_’ to names

.text

_main:

push.w20; parameter <y>

push.w10; parameter <x>

Advertising