Hello experties, I am a first year student in my university, and was given an assignment. I tried a bit and I am stucked 1/4 way. I am really noob in assembly language(I always got low marks especially in this subject).

So please help me....

Here is the question;


Here's the code I've made so far, correct me too if i'm wrong.

include irvine32.inc

.data
arrayA dword 10 DUP (0)
arrayB dword 100 DUP (0)

str1 byte "ArrayA Input : ",0
str2 byte "ArrayB Input Processing in 2 seconds... ",0
str3 byte "Array Processor Processing in 3 seconds... ",0
str4 byte " <=> ",0
str5 byte "Input Values : ",0

.code
main proc

;=======================================================================

;arrayA
mov ecx, lengthof arrayA
mov esi,0

;LOOP 1
L1:
mov edx, offset str5
call writestring
call readdec
mov ,eax
add esi,4
loop L1

mov edx, offset str1
call writestring

mov ecx, lengthof arrayA
mov esi,0

;LOOP 2
L2:
mov eax,
call writedec
add esi,4
loop L2

call crlf
call crlf

;=====================================================================

;arrayB
mov edx, offset str2
call writestring
call crlf

mov eax,2000
call delay

mov ecx,lengthof arrayB
mov ecx,10

;LOOP 3
L3:
mov eax,100
call randomrange
mov ,eax
call writedec
mov edx, offset str4
call writestring
call writehex
call crlf
Loop L3

call crlf

;======================================================================

;Array Processor
mov edx, offset str3
call writestring
call crlf

mov eax,3000
call delay

call crlf

;=====================================================================

exit
main endp

end main



I am using Textpad 4 btw...

Thanks!
Posted on 2010-03-11 04:16:27 by LuffyPSP
Looks fine... Don't just start with the next to-do point but create the output page next. So that you can see if it truly takes the numbers as entered and generates them as wanted.

Then implement the add functionality and add it to the output page and so on and so on.
Posted on 2010-03-11 05:24:48 by JimmyClif
Can you please give the example for the add functionality? That is the part where I got stuck actually, because I dont know how to start, just the ADD one is enough.

Thank you.
Posted on 2010-03-11 07:46:34 by LuffyPSP
Here's my friend's code, it has some problems though, cuz the program will stop working.

include irvine32.inc
.data

arrayA sdword 0,0,0,0,0,0,0,0,0
arrayB sdword ?
sum sdword ?
str1 byte "Enter integer:",0
str2 byte "ArrayA content:",0
str3 byte "ArrayB content:",0

.code
main proc

  ;enter arrayA
  mov ecx,lengthof arrayA
  mov esi,offset arrayA
L1:
  mov edx,offset str1
  call writestring
  call readdec
  mov ,eax
  add esi,4
  loop L1

  ;Display arrayA
  mov edx,offset str2
  call writestring
  call crlf

  mov ecx,lengthof arrayA
  mov esi,offset arrayA
L3:
  mov eax,
    add esi,4
  call writeint
  call crlf
  call writehex
  call crlf

  loop L3
  call crlf
;--------------------------------------------
;display arrayB in random range 0-99
  mov edx,offset str3
  call writestring
  call crlf

  mov ecx,lengthof arrayA
  mov esi,offset arrayA
L4:

  mov eax,
  add esi,4
  call Randomize
  call randomRange
  mov arrayB,eax
  call writeint
  call crlf
  call writehex
  call crlf

loop L4
call crlf

;--------------------------------------------
;Display result
;Add

mov esi,0
mov ecx,lengthof arrayA
mov eax,arrayA
L5:
  add eax,arrayB
  call writeint
  call crlf
  call writehex
  call crlf
  jmp next
next:
  add esi,8
  loop L5
  call crlf
  call crlf

exit
main ENDP
END main
Posted on 2010-03-11 07:54:38 by LuffyPSP
Sorry for the triple posting, I cannot seem to find the edit button.

Actually, I dont really understand the part where it says, Array Processor is processing as follows : ADD, MUL, etc.... I dont know what does it want so that is why I dont know how to do it....

Please explain and give example for that please...
Posted on 2010-03-11 09:47:08 by LuffyPSP
The tricky part of the "array processing" that I see is that it wants arrayA[1] added (etc.) to arrayB[0], and when we get to the end, arrayA[0] added to arrayB[9]. Have I got that right? (the print on your inclusion of the assignment is a little small for these tired old eyes) I think I'd handle that by doing the first (or last) as a special case, and then looping 9 times instead of ten for the "body" of it.

The example output page looks pretty fancy! Given that, I think I'd put the results from each operation into a separate array...


    ...
    xor esi, esi ; or "mov esi, 0"
    mov ecx, 9 ; or lengthof ArrayA - 1 ?
add_loop:
    mov eax,
    add eax, 
    mov , eax
    add esi, 4
    loop add_loop

; and do the last one...
    mov eax,
    add eax,
    mov , eax
    ; ret?


That's untested, and probably wrong in details, but "something like that". :)

JimmyClif says your code looks alright, but I have a question. Why are the arrays different sizes? You have to load ecx, and then overwrite it with the "correct" value:


mov ecx,lengthof arrayB
mov ecx,10


That's a minor issue. Your friend's code has a much bigger problem in the same place! He allocates only 9 items for arrayA, and only 1 for arrayB!!! He's overrunning his buffer. That's why it stops running. I guess the lesson in this is "first, allocate your buffers correctly!". The way you do it is okay, but they should really both (all?) be the same size. I'd:


%define ARRAY_SIZE 10 ; Nasm syntax... no '%' for Masm?
...
arrayA ARRAY_SIZE dup dd ?
...
mov ecx, ARRAY_SIZE ; or ARRAY_SIZE - 1
...


That would make it easy if next week's assignment was "okay, now do it with 20 items". I guess "lengthof" works for what you want (Nasm doesn't have it).

Does that get you any closer?

Best,
Frank

Posted on 2010-03-11 14:45:32 by fbkotler
Frank, I did spot that error on his friends code while his had enough for both of them.

I also started typing up the whole process of adding to A0 to B9 then looping 9 times but accidently (well, by habit) did the whole thing in dword size and scrapped it not to confuse Luffy ;)

Also at the same time I re-thought that i would really like him to generate the output first before having him to add or mul but i didn't want to sound too 'teacher'-y and decided to hold on my answer for awhile...

Cheers :)
Posted on 2010-03-11 15:18:34 by JimmyClif
I have some questions;

1) Why for the "add esi, 4", we use "4"?

2)
mov ecx,lengthof arrayB
mov ecx,10


whats the "correct" value? :p cuz I've been trying to put different value and it wont display 10 random values, as it will display something else.

3) As for the code you gave,

  xor esi, esi ; or "mov esi, 0"
    mov ecx, 9 ; or lengthof ArrayA - 1 ?
add_loop:
    mov eax,
    add eax, 
    mov , eax
    add esi, 4
    loop add_loop


this one gave the first value inserted on arrayA,

and this one,

   mov eax, 
    add eax,
    mov , eax


gave the last value inserted on arrayA

I cannot see where the ADD function takes place, and also how does the arrayA and arrayB related?

I am very sorry for my lack of knowledge, may you teach me the correct method for it.

Thank you very much.


Btw sorry for the small pic, Here's the big one;






Posted on 2010-03-11 18:00:05 by LuffyPSP
and another question, why is it my random values always produce the same number?

;arrayB
mov edx, offset str2
call writestring
call crlf

mov eax,2000
call delay

mov ecx,lengthof arrayB
mov ecx,10

;LOOP 3
L3:
mov eax,100
call randomrange
mov ,eax
call writedec
mov edx, offset str4
call writestring
call writehex
call crlf
Loop L3

call crlf


it looks random but when i see it many times, it is the same number actually...

EDIT : Sorry just saw that now there is an edit button.
Posted on 2010-03-11 18:07:11 by LuffyPSP

and another question, why is it my random values always produce the same number?


At a glance, your friend's code is doing something that yours does not prior to calling randomrange, and may be critical to the randomization functionality you are utilizing.

Review your friend's code and tell us what you think the possibilities may be in ensuring that the random number generator works as designed.
Posted on 2010-03-11 18:37:31 by SpooK
mov edx, offset str2
call writestring
call crlf

mov eax,2000
call delay

mov ecx,lengthof arrayA
mov esi,offset arrayA


;LOOP 3
L3:
mov eax,
add esi,4
call randomize
call randomrange
mov arrayB,eax
call writeint
mov edx, offset str4
call writestring
call writehex
call crlf
Loop L3

call crlf


thats my new code, and yeah now i got the right random values, but it ranges 0-10 only. How do i make it randomize from 0-99? cuz whenever i'm changing the codes it'll stop working.
Posted on 2010-03-11 18:49:54 by LuffyPSP

thats my new code, and yeah now i got the right random values, but it ranges 0-10 only. How do i make it randomize from 0-99? cuz whenever i'm changing the codes it'll stop working.


Try this instead and see if it helps...


call randomize
mov eax,
add esi,4
call randomrange
Posted on 2010-03-11 20:39:22 by SpooK
Thanks for the "big picture"! :)

Lots of questions... why "4" in "add esi, 4".... I ASSumed that the size of the individual elements in the array was dwords - 4 bytes each, so we'd need to add 4 to esi to get to the next one. JimmyClif suggests that this may not be correct. The assignment says "values", which could be anything. They also refer to "integer", which is a rather imprecise term, IMHO. When I was a lad, "the integers" were an infinite set of numbers, not just what would fit in... well, used to be 16 bits, then it was 32... I suppose it's 64 bits now... I still ASSume an "item" is 32 bits, I think, but if it isn't clear to you, ask for clarification. It makes a big difference!

There's a different addressing mode... if we wanted esi to be 0, 1, 2,..., we could do:


mov eax,


Valid multipliers are 1 (if we don't say) - good for a byte array, 2 - good for a word array (another ambiguous term - I mean 16 bits, 2 bytes - but sometimes it means "native machine word" - 32 or 64 bits, these days - Jonathan Bartlett's "PGU" book uses "word" like this), 4 - good for dword arrays (or single-precision floats), and 8 - good for double-precision floats or other 64-bit values. You can't just stick any random number in there. You're probably better off with "add esi, 4", but it's an alternative.

Speaking of random numbers... your best bet there is to RTFM on Irvine's library routines. The "usual" setup is that there's a routine you call to initialize it - once, not every time. Then to get random numbers, call another routine repeatedly. This will actually give a sequence of numbers that repeats, but not until after a long, long time. It looks to me like Irvine's "randomrange" wants the "range" in eax. But look it up - don't ASSume.


I cannot see where the ADD function takes place, and also how does the arrayA and arrayB related?


Mmmm, the add function takes place at the "add" instruction - the value from arrayA, in eax, has the value in arrayB added it it, and it's stored in a third array - which doesn't exist yet, I just made it up for the example. ArrayA and arrayB aren't really "related" - one is an array filled in by the user, the other is filled with random values. I think that's how it's supposed to go...

The assignment mentions "MUL/IMUL". I don't know what that means. Got to be one or the other, eh? Also, I just noticed, the assignment mentions ten values, but the example display screen only shows room for nine! I guess I'm not the only one who sometimes has trouble making myself clear! :)

Anyway, I agree with JimmyClif's suggestion to do it "one piece at a time". First fill one array with values gotten from the user, and display it. Next fill the other array with "random" values, and display it. Until those two parts are working properly, adding them together is never going to work! I suppose that's obvious, but some people seem to think they can tweak it so the "final result" is correct, even though the "parts" aren't. Not likely! (Jeff Duntemann even called his book "Step by Step"!)

So... keep steppin'! :)

Best,
Frank

Posted on 2010-03-12 00:40:56 by fbkotler
My latest code. Have some error though. But this one is a complete one. and i dont know how to fix the error. and if its fixed, the program will stop working when excuted...Please help...

include irvine32.inc

.data
arrayA dword 10 DUP (0)
arrayB dword 10 DUP (0)
arrayADD dword 10 DUP(0)
arrayMUL dword 10 DUP(0)
arrayNEG dword 10 DUP(0)
arrayOR dword 10 DUP(0)
arrayXOR dword 10 DUP(0)

str0 byte " ",0
str1 byte "ArrayA Input : ",0
str2 byte "ArrayB Input Processing in 2 seconds... ",0
str3 byte "Array Processor Processing in 3 seconds... ",0
str4 byte " <=> ",0
str5 byte "Input Values : ",0
str6 byte "Displaying Results :",0
str7 byte "ADD : ",0
str8 byte "MUL : ",0
str9 byte "NEG : ",0
str10 byte "OR : ",0
str11 byte "XOR : ",0
str12 byte "Array Processor Continue (y/n) : ",0
str13 byte "Array Processor Exit",0
str14 byte "Thank You For Using The Program",0

.code
main proc

START:

;=======================================================================

;arrayA user input
mov ecx, lengthof arrayA
mov esi,0

L1:
mov edx, offset str5
call writestring
call readint
mov ,eax
add esi,4
loop L1

call crlf
call crlf

;=====================================================================

;arrayB randomize numbers
mov edx, offset str2
call writestring
call crlf
mov eax,2000
call delay

mov ecx,lengthof arrayB
mov esi,0

L3:
mov eax,100
call randomrange
mov arrayB,eax
add esi,4
Loop L3



;======================================================================

;Array Processor
mov edx, offset str3
call writestring
call crlf

mov eax,3000
call delay

call crlf

;=====================================================================

;ADD (ArrayA + ArrayB)
mov ecx, lengthof arrayA
mov esi, 0
mov edi, 4
mov eax, 0

L5:
mov eax,arrayA
add eax,arrayB
mov eax,arrayADD
add esi,4
add edi,4
loop L5

mov eax,arrayA[36]
mov eax,arrayB[0]
mov arrayADD[36],eax

;=====================================================================

;MUL (arrayA * arrayB)
L6:
mov eax, arrayA
cdq
mov ebx, arrayB
imul ebx
mov arrayMUL, eax
add esi, 4
add edi, 4
loop L6

mov eax, arrayA[36]
cdq
mov  ebx, arrayB[0]
imul ebx
mov arrayMUL[36], eax

;====================================================================

;NEG (arrayA - arrayB)

mov ecx, lengthof arrayA - 1
mov esi, 0
mov eax, 0
L7:
mov eax, arrayADD
neg eax
mov arrayNEG, eax
add esi, 4
loop L7
mov eax, arrayADD[36]
neg eax
mov arrayNEG[36], eax

;====================================================================

;OR
mov ecx, lengthof arrayA - 1
mov esi, 0
mov edi, 4
mov eax, 0
L8:
mov eax, arrayA
or eax, arrayB
mov arrayOR, eax
add esi, 4
add edi, 4
loop L8
mov eax, arrayA[36]
or eax, arrayB[0]
mov arrayOR[36], eax

;====================================================================

;XOR
mov ecx, lengthof arrayA - 1
mov esi, 0
mov eax, 0
L9:
mov eax, arrayADD
xor eax, eax
mov arrayXOR, eax
add esi, 4
loop L9
mov eax, arrayADD[36]
xor eax, eax
mov arrayXOR[36], eax

;====================================================================

;Displaying output

;arrayA
mov ecx, lengthof arrayA
mov esi,0

L2:
mov eax,
call writeint
mov edx, offset str4
call writestring
call writehex
call crlf
add esi,4
loop L2

mov edx, offset str1
call writestring
call crlf

;arrayB
mov ecx, lengthof arrayB
mov esi,0

L4:
mov eax,
call writeint
mov edx, offset str4
call writestring
call writehex
call crlf
add esi,4
loop L4

;results
mov edx, offset str6
call writestring
call crlf

;display ADD
mov edx, offset str7
call writestring
call crlf
mov ecx, 10
mov esi, 0

L10:
mov eax, arrayADD
call writeint
add esi, 4
mov edx, offset str0
call writestring
call writehex
loop L10

call crlf

;display MUL
mov edx, offset str8
call writestring
call crlf
mov ecx, 10
mov esi, 0

L11:
mov eax, arrayMUL
call writeint
add esi, 4
mov edx, offset str0
call writestring
loop L11

call crlf

;display NEG
mov edx, offset str9
call writestring
call crlf
mov ecx, 10
mov esi, 0

L12:
mov eax, arrayNEG
call writeint
add esi, 4
mov edx, offset str0
call writestring
loop L12

call crlf

;display OR
mov edx, offset str10
call writestring
call crlf
mov ecx, 10
mov esi, 0

L13:
mov eax, arrayOR
call writeint
add esi, 4
mov edx, offset str0
call writestring
loop L13

call crlf

;display XOR
mov edx, offset str11
call writestring
call crlf
mov ecx, 10
mov esi, 0
L14:
mov eax, arrayXOR
call writeint
add esi, 4
mov edx, offset str0
call writestring
loop L14
call crlf

;=====================================================================

;Prompt the user if he/she wants to continue the program.
CHOOSE:
mov edx, offset str12
call writestring
call readchar
call writechar
call crlf
cmp al, 'y'
je START
cmp al, 'n'
je NEXT
jmp CHOOSE

;Termination message:
NEXT:
mov edx, offset str13
call writestring
call crlf
mov edx, offset str14
call writestring
call crlf

;=====================================================================

exit
main endp

end main
Posted on 2010-03-12 11:04:34 by LuffyPSP
LuffyPSP,

L5: loop ends with ecx being equal to zero. Next loop instruction will branch to L6: for 2**32 times in a row before ecx becomes zero again.
Posted on 2010-03-12 16:43:26 by baldr

i dont know how to fix the error. and if its fixed, the program will stop working when excuted...


No, no, no! When the error(s) are "fixed", the program will work. If it still doesn't work, the error(s) aren't "fixed"!

Besides the doozy Baldr spotted, I think I see a number of other errors. Mostly due to "brain flatulence" - you knew perfectly well what you wanted to do, you just screwed it up when you wrote it down! Reading over what you wrote may not help. I tend to "read what I intended" instead of what I wrote. Amazing, how blind we can be when we think we "know" what it says!

The first error I see is in the randomization routine. Did you decide, after looking it up, that we don't need "randomize" first? That's not the error I mean. Look closely at where you're storing the random numbers! "What's the add esi, 4 for?" would be a good question here! :)

Then, in your "ADD" routine, do you want to loop "lengthof arrayA", or one less than that?

In all of your "processing" routines, you're applying a "forward offset of 4" (can I call it that?) to arrayB. As I interpret the diagram in the assignment, the "forward offset" should be applied to arrayA, no? If I'm right, you can fix this easily by starting with edi at 0 and esi at 4. You'll have to change the last "odd case", too, probably.

Note that:


mov eax, arrayA


instead of using the second register (edi) will also work. This is not a bug, just an alternative. Also "not a bug", but a matter of "style"...


mov eax,
mov eax, arrayA


Both of these lines do exactly the same thing. Doesn't matter which you use, but it would probably be best to do it the same way every time. Nasm won't accept the second, so I prefer the first. Your best bet is to use the style your instructor prefers! (you have been paying attention in class, no?)

Then we fall into the "MUL" routine. As Baldr observes, you don't reinitialize ecx. You might reasonably think that a "loop" with ecx=0 wouldn't execute at all, but "loop" decrements ecx before it decides whether to jump again, so it'll execute the whole 4G times. This will mess up your display! (and everything else) You probably want to do esi and edi, too. Nice use of "cdq"... but you really don't need it here - "imul" multiplies eax by... whatever... and puts the result in edx:eax. "idiv" needs "cdq".

Then the "NEG" routine. You correctly observe that we've already got arrayA + arrayB in arrayADD, so don't need to "add" them again. Good optimization! But it means that we don't need the loop count to be "-1", and do the last one separately. I don't think it hurts, just mentioning it...

Then the "XOR" routine. This is seriously wrong, as I interpret the assignment. I think you're supposed to "xor" arrayA with ArrayB (according to the funny "pattern" in the diagram). You take a value from arrayADD and "xor" it with itself - which will result in zero, every time. Not the same as the "NEG" routine (as I understand it) - do it "more like the other ones". Is there not supposed to be an "OR" routine, too? (if you don't know the difference between "or" and "xor", this is a good time to learn)

And... that's all the errors I see! "How it looks" will probably be the judge of whether the display is right. Of course, none of it's going to be right until you get arrayB initialized correctly. If you'd done it like JimmyClif said, you'd know that! :)

Despite the few errors, you've got a pretty good "framework" there, I think. Shouldn't take long to work the kinks out of it.

Best,
Frank

Posted on 2010-03-12 18:13:34 by fbkotler
This is my final code;


;Section 02

include irvine32.inc
.data

arrayA sdword 10 DUP(0)
arrayB sdword 10 DUP(0)
arrayADD sdword 10 DUP(0)
arrayMUL sdword 10 DUP(0)
arrayNEG sdword 10 DUP(0)
arrayOR sdword 10 DUP(0)
arrayXOR sdword 10 DUP(0)

strA byte " ",0
strB byte "                          Array Processor Input",0
strC byte "                          Array Processor Output",0
strD byte " <=> ",0

str1 byte "ArrayA Input: ",0
str2 byte "ArrayB Input Processing In 2 seconds ....",0
str3 byte "Array Processor Processing In 3 seconds ....",0
str4 byte "ArrayA Content: ",0
str5 byte "ArrayB Content: ",0
str6 byte "Display Result: ",0
str7 byte "ADD : ",0
str8 byte "MUL : ",0
str9 byte "NEG : ",0
str10 byte "OR : ",0
str11 byte "XOR : ",0
str12 byte "Array Processor Continue (y/n) : ",0
str13 byte "Array Processor Exit",0
str14 byte "Thank You For Using The Program",0

.code
main proc



START:
  call clrscr

  mov eax, green + (black*16)
  call settextcolor
  mov edx,offset strB
  call writestring
  call crlf
  call crlf

  mov eax, white + (black*16)
  call settextcolor

  ;=======================================================

  ;ArrayA user input

  mov ecx, lengthof arrayA
  mov esi, 0

  L1:
  mov edx, offset str1
  call writestring
  call readint
  mov arrayA, eax
  add esi, 4
  loop L1

  call crlf

;========================================================

  mov edx, offset str2
  call writestring
  call crlf
  mov eax,2000
  call delay


;=======================================================

;arrayB randomize values from 0-99

  mov ecx, lengthof arrayB
  mov esi, 0

  L2:
    mov eax, 100
    call randomrange
    mov arrayB, eax
    add esi, 4
  loop L2

;=======================================================

  mov edx, offset str3
  call writestring
  call crlf

  mov eax,3000
  call delay
  call crlf



;=======================================================

;Add

mov ecx, lengthof arrayA-1
mov esi,0
mov edi,4
mov eax,0

L20:
  mov eax,arrayA
  add eax,arrayB
  mov arrayADD,eax
  add esi,4
  add edi,4
loop L20

mov eax,arrayA[0]
add eax,arrayB[36]
mov arrayADD[36],eax


;=======================================================

;MUL

mov ecx,lengthof arrayA-1
mov esi,0
mov edi,4
mov eax,0
L30:

  mov eax,arrayB
  cdq
  mov ebx,arrayA
  imul ebx
  mov arrayMUL,eax
  add esi,4
  add edi,4
loop L30

mov eax,arrayB[36]
cdq
mov ebx,arrayA[0]
imul ebx
mov arrayMUL[36],eax

;=======================================================

;NEG(arrayA+arrayB)

mov ecx,lengthof arrayA-1
mov esi,0
mov eax,0
L40:

  mov eax,arrayADD
  neg eax
  mov arrayNEG,eax
  add esi,4
  loop L40

  mov eax,arrayADD[36]
  neg eax
  mov arrayNEG[36],eax

;=======================================================

;OR

mov ecx, lengthof arrayA - 1
mov esi, 0
mov edi, 4
mov eax, 0

L50:
  mov eax, arrayA
  or eax, arrayB
  mov arrayOR, eax
  add esi, 4
  add edi, 4
loop L50

mov eax, arrayA[0]
and eax, arrayB[36]
mov arrayOR[36], eax



;=======================================================

;XOR

mov ecx, lengthof arrayA - 1
  mov esi, 0
  mov edi, 4
  mov eax, 0

  L60:
  mov eax, arrayA
  xor eax, arrayB
  mov arrayXOR, eax
  add esi, 4
  add edi, 4
  loop L60

  mov eax, arrayA[0]
  and eax, arrayB[36]
  mov arrayXOR[36], eax



;========================================================

;Array Processor Processing

mov eax, green + (black*16)
call settextcolor

mov edx, offset strC
call writestring
call crlf
call crlf

;=======================================================

;Display arrayA

mov eax, yellow + (black*16)
call settextcolor

mov edx, offset str4
call writestring
call crlf
call crlf

mov eax, white + (black*16)
call settextcolor

mov ecx, lengthof arrayA
mov esi, 0

L3:
  mov eax, arrayA
  call writeint
  add esi, 4
  mov edx, offset strD
  call writestring
  call writehex
  call crlf
  loop L3

  call crlf


;=========================================================

;display arrayB

mov eax, yellow + (black*16)
call settextcolor

  mov edx, offset str5
  call writestring
  call crlf
  call crlf

  mov eax, white + (black*16)
  call settextcolor


  mov ecx, lengthof arrayB
  mov esi, 0

  L5:
  mov eax, arrayB
  call writeint
  add esi, 4
  mov edx, offset strD
  call writestring
  call writehex
  call crlf
  loop L5

  call crlf

;=======================================================

;display result

mov eax, magenta + (black*16)
call settextcolor


mov edx, offset str6
call writestring
call crlf
call crlf

;=======================================================

;display ADD

mov eax, yellow + (black*16)
call settextcolor

mov edx,offset str7
call writestring
call crlf


mov eax, white + (black*16)
call settextcolor

mov ecx,10
mov esi,0

L7:
mov eax,arrayADD
call writeint
add esi,4
mov edx,offset strD
call writestring
call writehex
call crlf
loop L7

call crlf

;=======================================================

;display MUL

mov eax, yellow + (black*16)
call settextcolor

mov edx, offset str8
call writestring
call crlf

mov eax, white + (black*16)
call settextcolor

mov ecx,10
mov esi,0

L9:
mov eax,arrayMUL
call writeint
add esi,4
mov edx, offset strD
call writestring
call writehex
call crlf
loop L9

call crlf


;=======================================================

;display NEG

mov eax, yellow + (black*16)
call settextcolor

mov edx, offset str9
call writestring
call crlf

mov eax, white + (black*16)
call settextcolor

mov ecx, 10
mov esi, 0

L11:
mov eax, arrayNEG
call writeint
add esi, 4
mov edx, offset strD
call writestring
call writehex
call crlf
loop L11

call crlf

;=======================================================

;display OR

mov eax, yellow + (black*16)
call settextcolor

mov edx, offset str10
call writestring
call crlf

mov eax, white + (black*16)
call settextcolor

mov ecx, 10
mov esi, 0

L13:
mov eax, arrayOR
call writeint
add esi, 4
mov edx, offset strD
call writestring
call writehex
call crlf
loop L13

call crlf


;=======================================================

;display XOR

mov eax, yellow + (black*16)
call settextcolor

mov edx, offset str11
call writestring
call crlf

mov eax, white + (black*16)
call settextcolor

mov ecx, 10
mov esi, 0

L15:
mov eax, arrayXOR
call writeint
add esi, 4
mov edx, offset strD
call writestring
call writehex
call crlf
loop L15

call crlf


;===============================================================

;Prompt the user if he/she wants to continue the program.

CHOOSE:
mov edx, offset str12
call writestring
call readchar
call writechar
call crlf
cmp al, 'y'
je START
cmp al, 'n'
je NEXT
jmp CHOOSE


;Termination message:

NEXT:
mov eax, red + (black*16)
call settextcolor
mov edx, offset str13
call writestring
call crlf
mov edx, offset str14
call writestring
call crlf
call crlf

mov eax, white + (black*16)
call settextcolor

exit
main endp
end main
Posted on 2010-03-13 18:05:26 by LuffyPSP
Looks good. Does it work? Out of curiousity, what happens if the user enters "xyz" instead of a number?

Best,
Frank

Posted on 2010-03-14 10:08:26 by fbkotler
Yes it works. And I've presented it to the lecturer, and he satisfied with it...:D

If user input the xyz, it will appear as "0"...
Posted on 2010-03-14 12:55:57 by LuffyPSP

Yes it works.


Good!


And I've presented it to the lecturer, and he satisfied with it...:D


Even better! :)



Okay. The reason I ask is that I've helped people with a similar (simpler) assignment, using Dr. Carter's tut and software. He uses a call to scanf for the "get a number from the keyboard" chore, and scanf (IMHO) is mentally unbalanced. Enter "xyz", and the program goes completely haywire! Multiple instances of "You entered: (some large number)". It would completely trash your array! Not the student's fault, not Dr. Carter's fault - scanf is just "brittle". We can do better, and I'm glad Kip Irvine has!

Best,
Frank

Posted on 2010-03-14 18:20:03 by fbkotler