-1

I am trying to implement a function where it converts lower case to upper case right now, not affecting the punctuation or numbers. but this code seems to not be working. please help thank you!

void capital(char *x)
{
  __asm
  {
    PUSH EAX
    PUSH EBX
    PUSH ECX
    PUSH EDX
    PUSH ESI
    PUSH EDI

    mov ebx, string

next_char:
    lodsb
    test al, al
    jz done
    cmp al, 'a'
    bl next_char
    cmp al, 'z'
    bg next_char
    sub al, 'a'-'A'
    mov [esi-1], al
    jmp next_char

    POP EDI
    POP ESI
    POP EDX
    POP ECX
    POP EBX
    POP EAX
  }
Gunner
  • 5,780
  • 2
  • 25
  • 40
Evelyn
  • 43
  • 1
  • 2
  • 8
  • 2
    Is there a good reason why you are using inline assembly in a higher level language? – Leonardo Feb 03 '14 at 05:02
  • Can you fix up your paste & add the 'done' label? (or is that the problem? :D) – nevelis Feb 03 '14 at 05:06
  • Please search for related questions here, there are plenty similar ones: [here](http://stackoverflow.com/questions/12868884/converting-lower-case-to-upper-case-in-intel-8086-assembly-if-already-in-upper) and [here](http://stackoverflow.com/questions/21444089/implementing-a-toupper-function-in-x86-assembly) and [here](http://stackoverflow.com/questions/10394521/converting-from-lower-case-to-upper-case). – Jens Feb 03 '14 at 05:08
  • And what compiler are you using? – nevelis Feb 03 '14 at 05:08
  • _"but this code seems to not be working"_ could mean anything. Be more specific. – Michael Feb 03 '14 at 05:50
  • 2
    Are `bl` and `bg` valid instructions?? I'm willing to assume that the assembler decided that `bg` is a label (if you don't have adequate warnings enabled), but `bl` is a register name and should never have been accepted by an (Intel syntax) assembler. – Brendan Feb 03 '14 at 08:51

1 Answers1

1

The same home-assignment was asked here: X86 Assembly Converting lower-case to uppercase

1) Instead of moving the string address to EBX it should be moved to ESI, where LODSB will read it from implicitly.
2) bl, bg are not valid x86 instructions, use JL, JG instead.
3) Label done is not defined in your code, it should go just in front of POP EDI.
Community
  • 1
  • 1
vitsoft
  • 5,515
  • 1
  • 18
  • 31