News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

you guys are my last hope ;_;

Started by AssemblerNoob, February 26, 2014, 10:34:22 AM

Previous topic - Next topic

AssemblerNoob

Hey guys! As you can probably tell I am not only new to this forum, but to the Assembly language as a whole.

We are programming in 16-bit in my college class and well, the problem I'm having is that nothing my teacher writes down on the board works.

The laptop I'm using has Win 7-32bit installed, so I know that it should be able to run 16 bit programs. But it's not running the programs that's the problem it's that the programs themselves are useless.

Let me use an example, day 1 of my class we went over the cliche "Hello world" greeting code.  Here is how my teacher wrote it:


.model small
.stack 100h

.data
msg db 10,13, 'Hello World!$'

.code
main proc
mov AX,@data
mov DS,AX
mov AH,9h
lea dx,msg
int 21h
mov ah,04ch
int 21h
main endp
end main


After using masm and linking it, it spouted out a paragraph of gibberish in the dos box.

After wanting to punch myself in the face, I finally found some help online to rewrite it as follows:


         .model small
.586
.stack 100h

.data
msg db 10,13, 'Hello, my name is Bubbah.$'

.code
hello proc
mov AX, @data
mov ds, AX
mov dx, OFFSET msg
mov AH ,9h
int 21h
mov al,0
mov ah, 04ch
int 21h
hello endp
end hello


This code works no problem, flawlessly, pristine, excellent.

Can anybody explain to a noob like me why that is? I'm still in the stage of trying to absorb the basics of assembler, so for my own teachers' code not to work makes my mind blow a piston out of my skull.

I have thousands of other questions to ask, but if you guys could start out by explaining this to me I would be so grateful you have no idea.

I'm at my wits end here ;_;

Thank you!

dedndave

the only real difference is the processor
.586
not sure why that's required - i thought the default was 8086, and that should work

AssemblerNoob

Wait, both code snippets are the same? (aside from .586)

I don't understand... Why would only the latter work then?

dedndave

well - minor differences
the strings are different
the proc name is different
one sets the exit code to 0, the other does not
one uses LEA, the other uses MOV OFFSET

none of those differences should stop it from assembling and working

AssemblerNoob

Mind blown... I'm not sure why it didn't work before but now it does!!  :greensml:

I got another question. I'm writing a prog to add two numbers together and spit out the sum, however after you enter the first number to be added it skips the prog to the end. Could you take a look at it?


.model small
.stack 100h
.data
x db ?
y db ?
msg db 10,13,'Enter a value $'
msg2 db 10,13,'The sum is $'

.code
addt proc
mov AX, @data
mov ds, AX
mov ah,9h
lea dx,msg
int 21h

mov AH,1h
int 21h

sub al,'0'
mov x,al
lea dx,msg
mov ah,9h
int 21h

sub al,'0'
mov y,al
mov ah,9h
lea dx,msg2
int 21h

mov ah,2h
mov dl,x
add dl,y
add dl,'0'
mov ah,2h
int 21h

mov ah, 04ch
int 21h
addt endp
end addt


It only lets you enter the first number, then it just immediately spits out the last two lines "Enter a number" and "The sum is *" and ends itself.

Is there a line I'm missing to allow the user to enter the second number?

dedndave

mov ah,9h
int 21h

sub al,'0'
mov y,al


oops - forgot to read a char
mov ah,9h
int 21h

mov AH,1h
int 21h

sub al,'0'
mov y,al

AssemblerNoob

Omg... Thank you so much!!!

Programming is so complex yet so simple- I have much to learn!

with midterms coming up next week and a full time work and full time student schedule things get really hectic for me, so to have somebody reply and help as quickly and efficient as you is such a godsend you have no idea!

you'll probably see a lot from me in this forum from hereon out, I'm in it to win as they say.

Again, thank you!!!!  :t

dedndave

as a rule, homework is not allowed on this forum
however, you put in a lot of effort, and merely needed a little direction - so i don't mind helping   :P

AssemblerNoob

Thanks a lot! I'll be sure not to ask about homework then, as a matter of fact our homework this week was to write a program which lets you input 4 numbers and spits out the highest value among them... Oh yeah, I got it to work!!! :)

Anyways, I've been trying to challenge myself to get a better grasp of Assembler with... mixed results.

I tried out one of the more advanced practice questions for the latter part of the semester and it just wrecked me. It gave me parts of the code and I tried to fill in the rest with terrible results, I'm trying to move a bar from left to right but it just comes up as empty space.


.model small
.stack 100h
.data
bar db 8,' ','|','$'
bar2 db 8,' ',8,8,'|','$'
x dw 500

.code
bars proc
mov AX, @data
mov ds, AX

mov dl,'|'
mov ah,2h
int 21h

mov cl,79

again:

mov ah,9h
lea dx,bar
int 21h

call waste
dec cl
Jnz again

mov ah,9h
lea dx,bar2
int 21h

dec cl
Jnz again

bars endp
waste proc

push ax
push bx
push cx
push dx

again2:

mov   cx,79

again3:

mov ax,79
mul x
dec cx
jnz again3
dec ax
jnz again2

pop dx
pop cx
pop bx
pop ax

ret
waste endp
end waste
end bars



Now I got bar and bar2 in the .data, but it told me to include x DW 500,  What exactly does DW do? It stands for "define word" does it not? So I'm not to sure what exactly 500 is doing in relation to X.

Anyways I toss 79 into cl because I want it to repeat 79 times, then use dec cl to count it down and the JNZ condition once its done.

Here is where I get confused because I kind of just squished in bar2 and prayed for something to work, the help instructions tell me to add a call for "waste" but at this point my mind is just grasping at straws.

Now the "pop" and "push" code snippets were given to me in the practice section but I have no idea how they play into this or what it is that I'm doing with them.

If someone could explain to me exactly what is going on in there I'd appreciate it. I realize it's a bad idea to try and tackle things way above my skill level but I'm incredibly hungry to learn this thing.

I wish to one day create a program that cures my stupidity.

dedndave

SetConsoleCursorPosition

http://msdn.microsoft.com/en-us/library/windows/desktop/ms686025%28v=vs.85%29.aspx

for the "bar" string...
bar db ' |',24h      ;24h = '$'

each time you display the string, increment the X position   :biggrin:
the space will cover up the previous bar

dedndave

oops sorry
that's a win32 function - you need the INT 10h or INT 21h function - lol

        MOV    AH,02H        ;request set cursor function
        MOV    BH,0          ;page 0
        MOV    DX,080FH      ;row 8 column 15
        INT    10H

AssemblerNoob

Hmmm, that doesn't seem to do anything for me.

I'm trying to get the bar to go bouncing from left to right, yet even with set cursor position it shows nothing.

dedndave

ok
start with a simple program that displays the " |" string
then, it waits for a key press
then, it steps the cursor position and displays the string again

and that's all

when you get that working, you are half-way there
you just need to add a loop to step through N counts (79 would be a full line)
and - the hard part is to add a little time delay

time delays in DOS are not great to work with
you can get the BIOS tick count, add so many ticks, and wait for it to elapse

here is a description of INT 1Ah, AH=0
https://sites.google.com/site/liangweiqiang/Home/e5006/e5006classnote/jumptiming/int1ahclockservice

Shayaan_Mustafa

Hi!

In the post #1 the code works well with me too. I tried it on win7 32bit with MASM. Without running in DOSbox. I can help you and your first code will work too. If so, then let me know.

Thanks