# Introduction to the ZK World Compiler

The ZK World compiler compiles high-level ZK World contract code into assembly code supported by ZK WorldVM. The general pipeline flow is shown in Figure 12:

<figure><img src="https://1596861963-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIiKcuHbHZ9FnXtvk4nmm%2Fuploads%2FqVB0b49RFHXc6q5T63yw%2Fimage.png?alt=media&#x26;token=eeb2080a-19db-4b18-8d6e-b2606b0ef70a" alt=""><figcaption><p>Figure 12: ZK World-lang language and compiler pipeline</p></figcaption></figure>

As can be seen from the figure above, the front end of the compiler takes the high-level contract program as input and compiles it into LLVM intermediate representation (IR); the back end of the compiler takes the LLVM IR generated by the front end as input and compiles it into ZK World assembly code.

The assembly code is finally assembled, linked, loaded and executed by ZK WorldVM through the toolchain pipeline to generate traces.

To illustrate the compiler pipeline, here is an example of a typical u32 type sqrt operation, with two different versions of directive and oracle to show the code generation process.

A ZK World-lang high-level language program using as to calculate u32 type is following

Contract Standard Contract

Main (){

sqrt \_  test (4)；}

fn sqrt\_ test（u32 n）- >（u32）{

u32 b = u32  sqrt (n);

\36820;\ b\_;

}

}

An example of a ZK World-lang high-level language program for computing sqrt of type u32 is as follows:

Contract Standard Contract

Main (){

sqrt \_  test (4)；

}

fn sqrt \_  test（u32 a）- >（u32）{

U32 result=0;

If (a>3){

Result=a;

u32   x  =   a   /   2  +   1;

//Assuming a maximum number of iterations of 100

Is (u32 i=0; i<100; i++){

If (x>=result) interrupts;

Result=x;

x  =   ( a   /  x  +  x )   /   2;

}

}Otherwise, if (a!=0){

Result=1;

}

Feedback results

}}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://zk-world.gitbook.io/zk-world-white-paper/zk-world-compiler-an-ai-based-compiler-to-generate-risc-assemblies/introduction-to-the-zk-world-compiler.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
