Assembly Language homework help

  • Thread starter Mastur
  • Start date
  • #1
41
0

Homework Statement


I'm having hard time appreciating this topic since they're not discussed well and, as of now, I still don't have resources or sample programs.
We're required to display Az By Cx . . . Yb Za including spaces using DOS debug.

Homework Equations


The Attempt at a Solution


My code displays only AABBCCDDEE..XXYYZZ. We already have a program for displaying Aa Bb Cc ... Xx Yy Zz so I attempted to revise that code. But I'm so unfortunate.
Code:
:0100 mov ah,02
:0102 mov dl,41
:0104 int 21
:0106 push dx
:0107 mov cl,7a
:0109 int 21
:010B push dx
:010C inc dl
:010E dec cl
:0110 cmp dl,5b
:0113 jne 104
:0115 int 20
Am I doing it correctly or I'm mixing up different instructions?
 

Answers and Replies

  • #2
rcgldr
Homework Helper
8,770
569
The display character routine you're using (AH = 02, INT 21H), uses dl, not cl, so you'll need to figure out how to use dl for both the upper and lower case output. The program does push dx twice in the loop, but it nevers does a pop .... You probably don't need to use push ... you could just use xchg cl,dl , and clean up the code you already have. Most of the registers are saved (except for AL and maybe AH) with those INT 21 calls.
 
Last edited:
  • #3
35,202
7,005
Also, I think you're not looping back to the right line. Near the end you have jne 104, which transfers control back to memory address 104. The instruction at that address is int 21. When you use the DOS interrupt (int 21h), you need to set up the registers appropriately, which doesn't seem to be happening here.
 
  • #4
35,202
7,005
It's helpful to have an example program that functions close to what you need for this problem, but you should also be thinking about your algorithm, which is something like this.
Code:
count = 26
firstChar = 0x41 ('A')
lastChar = 0x7A ('z')
loop
  print firstChar
  print lastChar
  print newline
  increment firstChar
  decrement lastChar
  decrement count
until loop == 0
 
  • #5
315
0
Mastur,

You should tell us for what CPU that assembly is written.

Ratch
 
  • #6
41
0
Intel.

As of now, I was able to display only AzB (no space yet). I'll try it again later.
 
  • #7
35,202
7,005
Mastur,

You should tell us for what CPU that assembly is written.

Ratch
It looks like Intel 8086 assembly with the int 21h DOS instructions, which is confirmed by the OP.

Intel.

As of now, I was able to display only AzB (no space yet). I'll try it again later.
 
  • #8
41
0
Sorry if I cannot fully understand what you are saying. Anyway, I made another progress. Now it displays "A zByzCyzDyzEyzFyzGyzHyzIyzJyzKyzLyzMyzNyzOyzPyzQyzRyzSyzTyzUyzVyzWyzXyzYyzZyz". I just don't know why a space exist after A.

1387:0100 mov ah,02
1387:0102 mov dl,41
1387:0104 int 21
1387:0106 push dx
1387:0107 inc dl
1387:0109 xchg cl,dl
1387:010B int 21
1387:010D mov dl,7a
1387:010F int 21
1387:0111 dec dl
1387:0113 xchg dl,cl
1387:0115 cmp dl,5b
1387:0118 jne 104
1387:011A int 20

zy doesn't seem decrementing. Did I place an increment instruction right after the decrement?

Btw, anyone of you have sample codes for assembly language? I am using DOS debug. I can easily understand codes in a program rather than wordy descriptions.
 
  • #9
rcgldr
Homework Helper
8,770
569
Since you're trying, a bit more help this time. I'll get you started, see if you can finish this:

1387:0100 mov dl,41
1387:0102 mov cl,7a
1387:0104 mov ah,02
1387:0106 int 21
1387:0108 xchg cl,dl
1387:010A int 21
1387:010C xchg cl,dl
1387:010E inc dl
1387:0110 dec cl
...

As far as an assembler goes, I'm not sure where to get an old DOS compatable development set, such as Masm 6.11 and Codeview (a source level debugger). You could download and use Microsoft Visual C++ express, which includes Masm 7.0, but creating a new project is a bit complicated. You create an empty project, add the assembly code (.asm text file) as an exsiting item to the project, then you have to specify a custom build step to do the assembly. I can explain more details on this if you want to try this.
 
Last edited:
  • #10
41
0
WOW. Thank you very much for your help. I was able to do it. The code seems shorter than what I've been doing before.

Though, I have some questions regarding the code you've given.

1. xchg cl,dl means exchange the values of cl and dl, right? Why are there two xchg instructions? Exchanging them twice will just return them to their original places, right?

2. Why didn't you use push instruction?

It might sound stupid but I really want to know about this. I want to appreciate Assembly Language more than or at least the same as how I appreciated C# and C++. I'm google-ing it but it is not giving me the answer I wanted.

I want to know how to do that on C++, but I'm afraid I do not have enough time to focus on it, as you say, its bit complicated. It is because we also have our thesis to be accomplished.

Anyway, in-case I have enough time already, I'll be PMing you to know more about that. Again, thank you very much.

Edit: Since it is required to have spaces every after the two letters, hopefully I can do this now without asking for help!

Edit2: I was able to do it. I used push and pop even if I don't understand why.
 
Last edited:
  • #11
35,202
7,005
In the algorithm in wrote in post #4, add a command to print a space (0x20) after you print the second character and before you print the newline character. Presumably you already figured this out.

As far as the push and pop are concerned, the reason for using them is to be able to use a given register without permanently losing its value.

For example, if cx contains 20 and you need to use cx for something, you could do this:
Code:
push cx ; store CX value on stack
move cl, 7a
; do some stuff
pop cx ; restore save value from stack
Generally, each push instruction should have a pop instruction fairly close by, to leave the stack in the same in the same state it was in before the push.
 
  • #12
rcgldr
Homework Helper
8,770
569
Since it is required to have spaces every after the two letters, hopefully I can do this now without asking for help! ... I was able to do it. I used push and pop even if I don't understand why.
For this particular program, you don't have to use push and pop, just keep the display values in registers other than dl. INT 21 generally saves the registers (it does the pushes and pops for you), except for AL, which INT 21 normally uses for a return value.

Code:
1387:0100 mov ah,02
1387:0102 mov ch,41
1387:0104 mov cl,7a
1387:0106 mov dl,ch
1387:0108 int 21
1387:010A mov dl,cl
1387:010C int 21
1387:010E mov dl,20
1387:0110 int 21
1387:0112 inc ch
1387:0114 dec cl
1387:0116 cmp ch,5b
1387:0119 jne 0106
1387:011B int 20

If or when you get to using a proper assembler, masm 5.0 style version of this program:

Code:
cseg    segment
        assume  cs:cseg,ds:cseg,es:cseg,ss:nothing
        org     0100h
disp0:  mov     ah,02h
        mov     ch,41h
        mov     cl,7ah
disp1:  mov     dl,ch
        int     21h
        mov     dl,cl
        int     21h
        mov     dl,20h
        int     21h
        inc     ch
        dec     cl
        cmp     ch,5bh
        jne     disp1
        int     20h
cseg    ends
        end     disp0

masm 6.11 (or later) style version of code:
Code:
        .model  tiny,c
        .8086
        .code
        assume  cs:@code,ds:@code,es:@code,ss:nothing
        org     0100h
disp    proc    far
        mov     ah,02h
        mov     ch,41h
        mov     cl,7ah
disp1:  mov     dl,ch
        int     21h
        mov     dl,cl
        int     21h
        mov     dl,20h
        int     21h
        inc     ch
        dec     cl
        cmp     ch,5bh
        jne     disp1
        int     20h
disp    endp
        end     disp
 
Last edited:
  • #13
41
0
For this particular program, you don't have to use push and pop, just keep the display values in registers other than dl. INT 21 generally saves the registers (it does the pushes and pops for you), except for AL, which INT 21 normally uses for a return value.

Code:
1387:0100 mov ah,02
1387:0102 mov ch,41
1387:0104 mov cl,7a
[U]1387:0106 mov dl,ch[/U]
1387:0108 int 21
[U]1387:010A mov dl,cl[/U]
1387:010C int 21
1387:010E mov dl,20
1387:0110 int 21
1387:0112 inc ch
1387:0114 dec cl
1387:0116 cmp ch,5b
1387:0119 jne 0106
1387:011B int 20
I thought it can only hold one value. Or this two instructions are the same as xchg dl,cl?

And other than those you have used, what are the other registers that I can use? Is it like variable in high-level programming languages as long as I use only two letters?
 
  • #14
rcgldr
Homework Helper
8,770
569
Is it like variable in high-level programming languages as long as I use only two letters?
Yes, registers are like variables (except they are in the cpu instead of ram).

And other than those you have used, what are the other registers that I can use?
Registers used as 16 bit values:

ax
bx
cx
dx
si
di
bp (normally used as backup for stack pointer)
sp (stack pointer)

Some of the register halves can be used for 8 bit values:

ah
al
bh
bl
ch
cl
dh
dl

wiki articles:

wiki_x86.htm

wiki_x86_instructions.htm
 
Last edited:

Related Threads on Assembly Language homework help

Replies
12
Views
571
  • Last Post
Replies
20
Views
8K
  • Last Post
Replies
0
Views
2K
Replies
0
Views
5K
  • Last Post
Replies
6
Views
4K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
3
Views
10K
Replies
12
Views
4K
Replies
10
Views
1K
Replies
2
Views
5K
Top