d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Assembly Project Question > What's Wrong With My Code :/
Add Reply New Topic New Poll
Member
Posts: 9,525
Joined: Nov 5 2005
Gold: 1,338.00
Apr 5 2014 05:49pm
Hey, so basically I'm trying to convert the letters in testArr (a, b, c, d, e) from lowercase to capital letters and then display them. Here's my code so far, I'm not sure why but I'm getting an invalid operand type error.

I include a directory for some basic i/o functions (like call print_nl which just prints a new line, and print_char which prints whatever char is in the rdi register) which work, so I don't think the fault is with them.

Here's the actual code.

Quote (Makefile)
TARGET = labobj

AFILES = main.asm\
  convertdata.asm

include /usr/local/include/project.mak


Quote (main.asm)
%include "/usr/local/include/asm_io.inc"

section .data

testArr db '000a', '000b', '000c', '000d', '000e'

extern convertdata
global asm_main

asm_main:

mov rbx, testArr

push rbx
call printdata
pop rbx
;
call print_nl
;
mov rbx, testArr
push rbx
call convertdata
pop rbx
;
call print_nl
;
push rbx
call printdata
pop rbx
;
ret

printdata:

push RBP
mov RBP, RSP

mov rbx, [rbp + 16]

mov rdi, [rbx]
call print_char
mov rdi, [rbx + 1]
call print_char
mov rdi, [rbx + 2]
call print_char
mov rdi, [rbx + 3]
call print_char
call print_nl

mov rdi, [rbx + 4]
call print_char
mov rdi, [rbx + 5]
call print_char
mov rdi, [rbx + 6]
call print_char
mov rdi, [rbx + 7]
call print_char
call print_nl

mov rdi, [rbx + 8]
call print_char
mov rdi, [rbx + 9]
call print_char
mov rdi, [rbx + 10]
call print_char
mov rdi, [rbx + 11]
call print_char
call print_nl

mov rdi, [rbx + 12]
call print_char
mov rdi, [rbx + 13]
call print_char
mov rdi, [rbx + 14]
call print_char
mov rdi, [rbx + 15]
call print_char
call print_nl

mov rdi, [rbx + 16]
call print_char
mov rdi, [rbx + 17]
call print_char
mov rdi, [rbx + 18]
call print_char
mov rdi, [rbx + 19]
call print_char
call print_nl

mov RSP, RBP
pop RBP
ret


Quote (convertdata.asm)
%include "/usr/local/include/asm_io.inc"

section .data

global convertdata

convertdata:

push RBP
mov RBP, RSP

mov rbx, [rbp + 16]

mov al, [rbx + 3]
and al, 01000001b
mov rbx + 3, [al]

mov al, [rbx + 7]
and al, 01000010b
mov rbx + 7, [al]

mov al, [rbx + 11]
and al, 01000011b
mov rbx + 11, [al]

mov al, [rbx + 15]
and al, 01000100b
mov rbx + 15, [al]

mov al, [rbx + 19]
and al, 01000101b
mov rbx + 19, [al]

mov RSP, RBP
pop RBP

ret


thoughts?
Member
Posts: 25,336
Joined: Jun 3 2005
Gold: 2,442.01
Apr 6 2014 12:07am
i just use the shift key
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Apr 6 2014 03:07am


Abduct says:

This code is pretty messy, and if you ever post assembler or even work with it you should comment every line.

You should look into the lodsb, stosb, lea, cmp, jb, ja instructions as for what you have with like 70 lines of assembler I can almost do in less then 20.

Heres an example that I haven't tested, but it should give you a general idea. It loops until a nullbyte is met and changes each byte loaded in al to uppercase by subtracting a constant 'a' - 'A' from the lowercase character.

Code

start:
cld
mov $my_string, %esi
next_char:
lodsb
cmp %al, 'A'
jb is_uppercase
cmp %al, 'Z'
ja is_uppercase
sub %al, 'a' - 'A'
is_uppercase:
stosb
cmp %al, 0
jne next_char


Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Apr 6 2014 04:03am
Quote (Azrad @ Apr 6 2014 04:07am)
Abduct says:
   
    This code is pretty messy, and if you ever post assembler or even work with it you should comment every line.
   
    You should look into the lodsb, stosb, lea, cmp, jb, ja instructions as for what you have with like 70 lines of assembler I can almost do in less then 20.
   
    Heres an example that I haven't tested, but it should give you a general idea. It loops until a nullbyte is met and changes each byte loaded in al to uppercase by subtracting a constant 'a' - 'A' from the lowercase character.
   
   
Code
start:
            cld
            mov $my_string, %esi
    next_char:
            lodsb
            cmp %al, 'A'
            jb  is_uppercase
            cmp %al, 'Z'
            ja  is_uppercase
            sub %al, 'a' - 'A'
    is_uppercase:
            stosb
            cmp %al, 0
            jne next_char


Tell Abduct I said he really should be commenting every line of assembler. /troll
Member
Posts: 9,525
Joined: Nov 5 2005
Gold: 1,338.00
Apr 6 2014 07:35am
Quote (Azrad @ Apr 6 2014 03:07am)
Abduct says:
   
    This code is pretty messy, and if you ever post assembler or even work with it you should comment every line.
   
    You should look into the lodsb, stosb, lea, cmp, jb, ja instructions as for what you have with like 70 lines of assembler I can almost do in less then 20.
   
    Heres an example that I haven't tested, but it should give you a general idea. It loops until a nullbyte is met and changes each byte loaded in al to uppercase by subtracting a constant 'a' - 'A' from the lowercase character.
   
   
Code
start:
            cld
            mov $my_string, %esi
    next_char:
            lodsb
            cmp %al, 'A'
            jb  is_uppercase
            cmp %al, 'Z'
            ja  is_uppercase
            sub %al, 'a' - 'A'
    is_uppercase:
            stosb
            cmp %al, 0
            jne next_char


NICE! Thanks. :P
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll