5 Replies - 2111 Views - Last Post: 02 December 2012 - 08:38 PM

#1 Bobby1414  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-November 12

Assembly code problem

Posted 02 December 2012 - 07:01 PM

I'm writing assembly code and I'm a bit out of my element. I'm having some difficulty getting this code to print the Uppercase characters to lowercase. Any suggestions? Here's what I have so far. Can anyone help me? I'm doing this using the EMU8086 which is designed for an Intelx86. Thanks in advance



org 100h


jmp start

string db 20, 22 dup('?')
revstring db 20, 22 dup('?') 
size dw 4 


new_line db 0Dh,0Ah, '$'

start:

lea dx, string

mov ah, 0ah
int 21h 

mov bx, dx
mov ah, 0
mov al, ds:[bx+1]
add bx, ax 

mov byte ptr [bx+2], '$'

lea dx, new_line
mov ah, 09h
int 21h


lea bx, string

mov ch, 0
mov cl, [bx+1] 
mov size, cx 

jcxz null 
add bx, 2 

upper_case:

cmp byte ptr [bx], 'a'
jb ok
cmp byte ptr [bx], 'z'
ja ok

and byte ptr [bx], 11011111b 

ok:

mov ah, byte ptr [bx]
push ax

inc bx 
loop upper_case

mov cx, size

lea bx, revstring

reverse:
pop ax
mov byte ptr [bx], ah
inc bx 
loop reverse

mov byte ptr [bx],'$' 

lea dx, revstring
mov ah, 09h
int 21h

mov ah, 0
int 16h


null:
ret 


Is This A Good Question/Topic? 0
  • +

Replies To: Assembly code problem

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: Assembly code problem

Posted 02 December 2012 - 07:16 PM

Let's move this on over to the Assembly Forum and to keep track of any other answers, cross posted Help displaying Uppercase to lowercase

Not posting that link..
Was This Post Helpful? 0
  • +
  • -

#3 Bobby1414  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-November 12

Re: Assembly code problem

Posted 02 December 2012 - 07:19 PM

I thought this was assembly section?



*** Edit ***
No, you posted in the "Other" section

This post has been edited by GunnerInc: 02 December 2012 - 07:23 PM

Was This Post Helpful? 0
  • +
  • -

#4 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: Assembly code problem

Posted 02 December 2012 - 07:22 PM

Take a look at an ASCII table:
http://www.cdrummond...files/ascii.htm

cmp byte ptr [bx], 'a'
jb ok
cmp byte ptr [bx], 'z'
ja ok


Your checking to see if the value in bx is below 97 (a) and above 122 (z) so it will and -33 to everything else.. is that what you want?

Your going to need to use 4 cmps (maybe 5 or 6) to get this to work.
Was This Post Helpful? 0
  • +
  • -

#5 Bobby1414  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-November 12

Re: Assembly code problem

Posted 02 December 2012 - 07:47 PM

took your advice and tried this with the same error still

cmp byte ptr [bx], 'a'
jb ok
cmp byte ptr [bx], 'z'
ja ok                
              
and byte ptr [bx], 11011111b ;
                           
cmp byte ptr [bx], 'Z'
jb ok              
cmp byte ptr[bx], 'A'
ja ok

and byte ptr [bx], 11011111b ;



I'm so confused. I tried this but it continues to give me AA when i input a value of AA.
Was This Post Helpful? 0
  • +
  • -

#6 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: Assembly code problem

Posted 02 December 2012 - 08:38 PM

So, you need to reverse the string (which you got down) and change upper to lower and lower to upper like this?
Attached Image

Have a question for you though... when you give someone your phone number, do you give it in binary numbers or decimal? Why use binary numbers?

It's late and I need sleep, so I will leave you with this:
upper_case:  
  mov al, byte ptr [bx]
  cmp al, "A"
  jb  CheckLower
  cmp al, "Z"
  ja  CheckLower
  add byte ptr [bx], " "  
  jmp ok

CheckLower:
  cmp al, "a"
  jb ok
  cmp al, "z"
  ja ok
  sub byte ptr [bx], " "

ok:

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1