0

I am trying to convert a C++ function code that converts passed string argument to UPPERCASE, into inline assembly code. Below is what i did:

// Funtion to convert each letter of employee name to uppercase. 
// Input : employee structure object as refrence.
void capitalise_name(employee &emp) 
{ 
    // //for loop to parse each letter the employee name
    // for (int i = 0; i < emp.name.length(); ++i) 
    // { 
    //     //convert the letter to uppercase
    //     emp.name[i] = toupper(emp.name[i]); 
    // } 
__asm__
(
    "mov ecx, emp.name"
    "call toUpper"
    "mov eax,1"
    "mov ebx,0"
    "int 80h"
"toUpper:"
    "mov al,[ecx]"     
    "cmp al,0x0"
    "je done"
    "cmp al,'a'"
    "jb next_please"
    "cmp al,'z'"
    "ja next_please"
    "sub al,0x20"      
    "mov [ecx],al"    

"next_please:"
    "inc ecx"          
    "jmp toUpper"
"done:" 
);
}

When i am compiling this program i am getting below error:

> Executing task: C/C++: g++.exe build active file <

Starting build...
C:\Data\mingw32\bin\g++.exe -fdiagnostics-color=always -g "C:\Users\rawat\Downloads\New folder\delivery\program.cpp" -o "C:\Users\rawat\Downloads\New folder\delivery\program.exe"
C:\Users\rawat\AppData\Local\Temp\ccRQyKCt.s: Assembler messages:
C:\Users\rawat\AppData\Local\Temp\ccRQyKCt.s:1003: Error: too many memory references for `mov'

Build finished with warning(s).

Terminal will be reused by tasks, press any key to close it.

Please suggest how can i resolve it thanks!

luck
  • 1
  • 1
  • There are plenty of problem with your inline assembly, using the wrong syntax being only one of them. A large problem is that you will have only a single string containing `"mov ecx, emp.namecall toUppermov eax,1.."` and so on. Another problem is that you *call* `toUpper` as a function, but you never `ret` from it. And what is the `int 80h` supposed to do? It's commonly used for system calls in e.g. Linux, but in the shown (but commented out) C++ code there's no system call. – Some programmer dude Mar 29 '22 at 10:54
  • 1
    @Someprogrammerdude: EAX=1 is `__NR_exit`, so that `int 80h` would exit the whole program if it was ever reached. IDK if that's what was intended, but it at least stops execution from going past that point... if there was a `ret` in `toUpper` to bring execution back to that point. – Peter Cordes Mar 29 '22 at 10:57
  • @PeterCordes One problem is that there *is* a `ret` in the program, implicitly create by the compiler for the `capitalise_name` function itself. That would then return from `call toUpper` to that `exit` syscall. – Some programmer dude Mar 29 '22 at 11:00
  • you'd have to pick a different title for your question and then it wouldn't be closed, like "what's wrong with my program". – user1095108 Mar 29 '22 at 11:19

0 Answers0