Skip to content

ZCPU HL-ZASM C structs don't work correctly #69

@EnoSkyFire

Description

@EnoSkyFire

1. The Problem

The current structs that are implemented do not work correctly. There are two issues. First issue is the struct returned in a function is not correct. Secondly, when I use #pragma CRT ZCRT with void main(){}, my returned struct gives an address value.

2. First issue - returning structs

DerelictDrone posted this image with working code were 2D vector addition is executed but in the result the register R2 should be 4 and not 3. I tested this code and I get the same result. The issue lies with returning the struct since outputting x and y within the function itself gives the correct values. source: (#17)
problem

3. Second issue - using void main() {}
Furthermore, when I try using structs with #pragma CRT ZCRT and with void main(){} instead of the main label, the returned struct has an address value. See code and result below.

Code:

//#pragma set OutputFinalListing true
#pragma CRT ZCRT

//jmp main

struct vec2 {
    float x;
    float y;
};

vec2 addvec(vec2 v, vec2 v2) {
    v.x += v2.x;
    v.y += v2.y;
    return v;    
    
}

vec2 v;
vec2 v2;

//main:
void main() {
    v.x = 1;
    v.y = 2;
    v2.x = 3;
    v2.y = 4;
    
    MOV R0,v.x
    MOV R1,v.y
    OUT 0, R0
    OUT 1, R1
    
    v = addvec(v,v2);
    
    MOV R2,v.x
    MOV R3,v.y
    OUT 2, R2
    OUT 3, R3
    
    MOV R4,v2.x
    MOV R5,v2.y
    OUT 4, R4
    OUT 5, R5
    
    v2 = v
    
    MOV R6,v2.x
    MOV R7,v2.y
    OUT 6, R6
    OUT 7, R7
}

Result:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions