+ Reply to Thread
Results 1 to 4 of 4

Thread: Zyelios C or Assembly Programming Tutorial

  1. #1
    Wire Noob limlik's Avatar
    Join Date
    Jun 2007
    Posts
    27

    Default

    Ok I am an uber noob to CPU. Which language is better to learn? Can someone make an example script for me to learn with? If you can make it something that When one button is pushed a value that starts at 50 is raised by 10 and when the other is pushed make it lower by 10. Is it possible for someone to write it in both Languages so I can see which I prefer?
    A great father to son quote from my dad. "The higher you set your ambitions the harder your going to hit the ground."

  2. #2
    Wire Sofaking Fatal_Exception's Avatar
    Join Date
    Oct 2007
    Location
    New Zealand
    Posts
    412

    Default

    Both of these examples are functionally equivalent, even though they use slightly different styles.

    Inputs:
    port0 - add button
    port1 - subtract button

    Outputs:
    port0 - result

    C:
    Code:
    #include <clib.c>
    
    int number = 50;
    
    main()
    {
    ******while(true)
    ******{
    ************if(inport(0) == 1)
    ******************number += 10;
    ************else if(inport(1) == 1)
    ******************number -= 10;
    
    ************outport(0, number);
    ******}
    }
    ASM:
    Code:
    org 0;
    alloc number,50;
    jmp main;
    
    add:
    mov eax,#number;
    add eax,10;
    mov #number,eax;
    mov port0,eax;
    jmp main;
    
    subtract:
    mov eax,#number;
    add eax,-10;
    mov #number,eax;
    mov port0,eax;
    jmp main;
    
    main:
    cmp port0,1;
    je add;
    cmp port1,1;
    je subtract;
    jmp main;

  3. #3
    Wire Noob limlik's Avatar
    Join Date
    Jun 2007
    Posts
    27

    Default

    Thanks, when you labeled the first one as C, is that the actual C language or a CPU variant?
    A great father to son quote from my dad. "The higher you set your ambitions the harder your going to hit the ground."

  4. #4
    Wire Sofaking Fatal_Exception's Avatar
    Join Date
    Oct 2007
    Location
    New Zealand
    Posts
    412

    Default

    The CPU variant, though it&#39;s not really that much different from real C, syntax wise.

    For comparison, a real C equivalent might look like this:
    Code:
    #include <stdio.h> // Include the standard i/o library, which contains printf().
    
    int number = 50;
    
    bool isPressed(int buttonID)** // Function that takes an integer as a parameter, and returns a boolean value 
    ****************************** // (true/false)
    {
    ** // Code to get the state of a button would go here
    ** // Return true or false depending on state
    }
    
    int main()
    {
    ** while(true)** // True makes this an infinite loop. Most real programs would have some exit condition here 
    **************** // instead of true.
    ** {
    ******if(isPressed(0))
    ******** number += 10;** // This is equivalent to "number = number + 10"
    ******else if(isPressed(1))
    ******** number -= 10;
    
    ******printf("%d",number);** // printf() outputs to the screen in a console application (well usually anyway).
    **************************** // "%d" is a code that indicates it should output an integer.
    ** }
    
    return 0;** // Real C programs should return a value of 0 to the operating system on successful exit
    }
    The only real differences are the use of printf() to output to the screen, main() returning a value, and the IsPressed function which would be written to get the state of a button in real life.

    There is one difference, which I didn&#39;t correct for simplicity. The regular wiremod screens simply display a single number, replacing it every time. If this program were to be run as-is (assuming isPressed() was replaced by a real function that did something) the output would be something like "5050505050505050505060606050505050504040405050504 0504040...", filling your screen very quickly. You could change the printf() to "printf("%d\n",number);" to have a newline after each ("\n" is the code for a new line), or use a function to clear the screen.

+ Reply to Thread

Similar Threads

  1. Assembly Programming Tutorial
    By Black Phoenix in forum CPU Tutorials
    Replies: 114
    Last Post: 03-25-2011, 02:37 PM
  2. Zyelios C
    By Black Phoenix in forum CPU, GPU, and Hi-speed Discussion & Help
    Replies: 172
    Last Post: 02-18-2009, 05:10 AM
  3. CPU Assembly Tutorial?
    By CaptainPoncho in forum Installation and Malfunctions Support
    Replies: 0
    Last Post: 02-21-2008, 06:03 PM
  4. Zyelios Editor bug?
    By scasbyte in forum CPU, GPU, and Hi-speed Discussion & Help
    Replies: 4
    Last Post: 12-01-2007, 08:23 AM
  5. Zyelios's CPU outputs
    By wokkel in forum CPU, GPU, and Hi-speed Discussion & Help
    Replies: 4
    Last Post: 11-10-2007, 01:22 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots