[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.8

I need help understanding a sample program (x86)

Asked by nocturn4l in Assembly Programming Language, Miscellaneous Programming

This was the sample program given to us.. and from this we are supposed to write a program that will prompt the user for a list of unsigned integers less than 101 (no error checking) (if user enters 101 that indicates the end of input), which will then compute and print out the count, the total, and the integer average.

This is due tomorrow and I'm completely stuck.. and I guess the only way i'll be able to write this is if i can at least understand the sample program given below  (though if you'd like to write it for me [by tonight] i'll paypal you-email me, i'm desperate)


SAMPLE CODE: takes a number from the user and does a countdown:  example output

Enter second to countdown? 3
T minus 3
T minus 2
T minus 1
blastoff

anyway ok so on to the questions where i'm having trouble understanding the sample code given..

EDIT: 1a) why is the first loop even there? it's only inputting one number from the user.... if it does loop.. i dont get this line here:

cmp al, cr
je endwl

i understand that when it compares cr to al it exits the loop if it does ssomething..but what is it comparing?  what's in al and what's in cr.. is 13 in cr?  if so that doesn't make sense at all..

1b) after the first loop.. it says that the number is stored in dx... for testing purposes.. how can i display to the screen what's stored in dx? or maybe do it through the assembler? (i'm using masm)

i know to display stuff is somethin similar to:

mov      dx, offset newline
mov      ah, 09h
int      21h

i still don't understand how to just output to the screen what's in the register dx though.  i'm just asking this for my general understanding i guess.. sigh i dont really know where to start.. right now i'm just trying to decipher this program..


2) where in the program is it outputting to the screen the decremented numbers?  i'm assuming it's the one under the comment ";;output character in dl"
mov ah, 02h
int 21h

but this is where i'm confused.. where is it getting the value to output from?  it says from dl... but it just has a '0' in it? or maybe from the stack that pushed dx?  i don't understand the while2 and while3 loop at all that's supposed to be outputting to the screen

3)  what's the purpose of these commands and what is it exactly doing

xor si, si
xor dx, dx

4)  why is si being incremented?

inc si

5?  what is "add dl, '0'" doing?


i'm thinking if i can just maybe understand what these lines are doing i can maybe understand how to make this program




As far as the program that i'm supposed to write is concerned... the sample program seems pretty straight forward.. but how the heck am i supposed to store all the data for the count, total, and average - are there enough registers for that?


ps - program assignment and sample *.asm files are in attached zip (rename *.txt to *.asm)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
title	Count Down
	.model	small
	.stack	100h
 
	CR = 13
	LF = 10
	EOS = '$'
 
	.data
prompt	db	"Enter second to count down? ", EOS
tminus	db	"T minus ", EOS
blastof	db	"blast off", EOS
newline	db	CR, LF, EOS
count	dw	?
  
	.code
main	proc
	mov	ax, @data		; setup data segment reg
	mov	ds, ax
 
	mov	dx, offset prompt
	mov	ah, 9h			; display string function
	int	21h			; call os
	
;
;getud
; read a number from the stdin, no error checking
	mov	dx, 0	; running sum = sum * 10 + new digit
	mov	cx, 10	; base 10
while1:	mov	ah, 01h	; get a digit
	int	21h
	cmp	al, cr	; if cr, then done
	je	endw1
	sub	al, '0'	; turn ascii digit to binary
	mov	ah, 0	; wordsize digit
	mov	bx, ax	; save new digit
	mov	ax, dx	; sum * 10
	mul	cx	;
	mov	dx, bx	; get back new digit
	add	dx, ax	; now + new digit
	jmp	while1	; next digit...
endw1:
	;;;number is in dx
 
	mov	count, dx
 
	mov	dx, offset newline
	mov	ah, 09h
	int	21h
 
; main loop - output t minus <second> lef
 
while4:	cmp	count, 0
	jz	endw4
 
	mov	dx,offset tminus
	mov	ah, 09h
	int	21h
 
	mov	bx, count
 
; number to output is in bx
 
	mov	cx, 10		;
	xor	si, si		;
while2:	mov	ax, bx		;
	xor	dx, dx		;
	div	cx		;
	mov	bx, ax		;
	add	dl, '0'		;
	push	dx		;
	inc	si		;
	cmp	bx, 0		;
	jne	while2		;
 
while3:	pop	dx		;
 
	;;output character in dl
	mov	ah, 02h
	int	21h
 
	dec	si		;
	jne	while3		;
 
	mov	dx, offset newline
	mov	ah, 09h
	int	21h
 
	dec	count
	jmp	while4
endw4:	mov	dx,offset blastof
	mov	ah, 09h
	int	21h
 
	
	mov	al, 0			; exit code 0
	mov	ah, 4ch			; return to os
	int	21h			; call os	
 
main	endp
      	end	main			; execution entry point
Attachments:
 
program assignment doc and sample *.asm files given to help write the program
 
[+][-]10/25/09 08:35 PM, ID: 25659548Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/26/09 02:03 AM, ID: 25660576Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Assembly Programming Language, Miscellaneous Programming
Sign Up Now!
Solution Provided By: Infinity08
Participating Experts: 2
Solution Grade: A
 
[+][-]10/26/09 07:59 AM, ID: 25662888Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/26/09 08:19 AM, ID: 25663125Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/26/09 02:15 PM, ID: 25666996Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/26/09 02:32 PM, ID: 25667154Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/26/09 02:39 PM, ID: 25667201Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/26/09 02:40 PM, ID: 25667218Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/26/09 03:11 PM, ID: 25667492Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625