-1

I'm trying to write an assembly program in 8086 TASM that will transform all lowercase letters into uppercase. I'm new to this assembly language programming so I'll really like a hint into what I'm doing wrong.Any help would be great,thank you.So my code so far is:

data segment 
sir2 dw 10 dup(?),'$'
sir1 dw 10,?,11 dup(?)
msg1 db 10,13,"introduceti sirul:$"
msg2 db 10,13,"sirul convertit este:$"
len dw ?
data ends

assume ds:data,cs:code
code segment

start:
    mov ax,data
    mov ds,ax
    xor ax,ax
    xor cx,cx
    xor dx,dx
    xor si,si
    mov ah,09h
    lea dx,msg1
    int 21h
    xor dx,dx
    mov ah,0Ah
    lea dx,sir1
    int 21h
    mov cx,sir1[1]
    mov ch,0
    mov len,cx
    mov ch,0
    mov si,2
    dec cx

verify:
    cmp sir1[si],97
    jg uppercase
    inc si
    loop verify

uppercase:
    cmp cx,0

    je endd
    sub sir1[si],20h
    inc si
    dec cx
    jmp verify
endd:
    xor bx,bx
    mov bx,sir1
    mov sir2,bx
    xor dx,dx
    mov ah,09h
    lea dx,sir2
    int 21h
    mov ah,04ch
    int 21h
code ends
end start
lurker
  • 56,987
  • 9
  • 69
  • 103
Lola
  • 218
  • 1
  • 11
  • 2
    Possible duplicate of [Assembler switch lower case for upper case and vice versa](https://stackoverflow.com/questions/37131194/assembler-switch-lower-case-for-upper-case-and-vice-versa) – sivizius Jun 21 '18 at 21:51
  • @sivizius: this is a debugging-help question, not a request for a different implementation altogether. As such, it's off topic because it doesn't say what actually happens (what errors, etc.), so it's not a [mcve], and http://idownvotedbecau.se/nodebugging/. But it's not a dup. And that question is a pretty clunky implementation, especially with the numeric constants instead of `'a'` or whatever. [How to access a char array and change lower case letters to upper case, and vice versa](https://stackoverflow.com/q/35932273) has much cleaner alphabetic-character detection. – Peter Cordes Jun 22 '18 at 00:10
  • You can take a far easier approach if you look at the binary representation of upper and lower case letters side by side. You'll see a very useful pattern that would allow you to simply `OR` against a bit mask to convert. – David Hoelzer Jun 22 '18 at 02:49
  • 1
    If you want other people to review your code then you need to add comments. Good ones, like for xor si,si don't just say "set the si register to 0", explain why 0 is a good choice. It isn't btw. Being forced to reason about what the code does is an excellent way to avoid bugs. A debugger helps you find the other ones. – Hans Passant Jun 22 '18 at 11:11
  • 1
    this task was already implemented multiple times (see duplicates). why should we help to debug some non-commented, non-obvious and for this task y too complicated code? a simple `cmp al, 'a'` `jb nope` `cmp al, 'z'` `ja nope` `and al, (0xff-'a'+'A')` `nope:` will do the task – sivizius Jun 22 '18 at 15:01

1 Answers1

1

Not a complete solution, because it looks as if you want to do the assignment on your own. The pseudocode you want is something like this:

Set the count to 0
For each byte b of input
  if b ≥ 'a'
    if b ≤ 'z'
      Subtract (`a' - 'A`) from b

  Increment the count

Set the following byte to the terminator character '$'

By the way: It was probably your prof who chose to have you write a 16-bit MS-DOS program. If any CS prof is reading this, I would strongly suggest that a better way to teach assembly language is as a subroutine called from a simple test driver in a HLL. Modern, free compilers for many languages and operating systems are completely capable of linking together object files written in different languages! Furthermore, this is a lot closer to the real-world uses of assembly today: writing low-level kernel code, examining compiled code to see what's really going on, and hand-optimizing sections of a larger program critical to the performance.

Davislor
  • 14,674
  • 2
  • 34
  • 49
  • "who chose to have you write a 16-bit MS-DOS program". Most probably the answer will be " We make it this way for 30 years now, what was good for us, is also good for you, young fellow-me-lad !" – Tommylee2k Jun 22 '18 at 07:43