Jump to content

Recommended Posts

Posted

Working with strings in ASM(32bit) looks difficult, especially when passing or returning strings. 
Any help on how to pass or return strings like ("Hello World!") in ASM, or how to convert the below code to ASM :P

Basic AutoIt code: if a string matches then ContinueLoop.

__Lp(20, '7;8;9')
Func __Lp($cnt, $str)
    Local $addup = 0
    Local $stepUp = 0
    $str = StringSplit($str, ';', 2)
    For $i = 0 To $cnt
        If $i = $str[$stepUp] Then
            If ($stepUp < UBound($str) - 1) Then $stepUp += 1
            ContinueLoop
        EndIf
    $addup += $i
;    ConsoleWrite('> ' & $i & @crlf)
    Next
    Return $addup
EndFunc

 

Equivalent C code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// Split semicolon-separated integers into a dynamically allocated array
int* splitInts(const char* str, const char* delim, int* outCount) {
    int* result = NULL;
    int count = 0;
    char* temp = strdup(str);  // Duplicate input to avoid modifying original
    char* token = strtok(temp, delim);

    while (token != NULL) {
        result = realloc(result, (count + 1) * sizeof(int));
        result[count++] = atoi(token);
        token = strtok(NULL, delim);
    }

    free(temp);
    *outCount = count;
    return result;
}

int __Lp(int cnt, const char* str) {
    int skipCount = 0;
    int* skipList = splitInts(str, ";", &skipCount);
	int addUp = 0;
    int stepUp = 0;

    for (int i = 0; i <= cnt; i++) {
        if (stepUp < skipCount && i == skipList[stepUp]) {
            if (stepUp < skipCount - 1) stepUp++;
            continue;
        }
//  printf("%d\n", i);
	addUp += i;
    }

    free(skipList);  // Free dynamically allocated memory
	return addUp;
}

int main() {
    __Lp(20, "7;8;9");
}

 

  • Developers
Posted
2 hours ago, jugador said:

Any help on how to pass or return strings like ("Hello World!") in ASM, or how to convert the below code to ASM :P

... and what exactly is the AutoIt3 question?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...