Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

HELP ME PLEASE!!!!

Would u plz help me to do this assembly language question?

Write a program that diaplay a volcabulary at 100 random screen lpcations with differnt colors,using a tining delay of 100-milliseconds.The colors are numbered from 0 to 15,so you can use a loop to generate differnt colors.
*Use the GetMaxYY procedure to determine the current size of console window.

1.Ask the user to input their name.
2.Calculate the time they use to input into milliseconds.Then,multiply this time by 100 to get a bigger number.Save and name this number as MyIntervalTime.
3.Declare 100 vocabularies for display.
4.The Interval time between each volcabulary is MyIntervalTime.
5.Randomly get one volcabulary from database above.
6.Display them one-by-one until we have 10 vocabularies in the same screen.Do not forget to change colors for each vocabulary.
7.When we have 10 vocabularies,clear screen.Then,start from displaying only one vocabulary.

Thank you.
«1

Comments

  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : Would u plz help me to do this assembly language question?
    :

    Most of this isn't an assembly language question - more of a design one.
    What part do you need help with? Where are you stuck at?
    (And also, what functions are available to you to print the output and get input from the user?)


    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • palm44palm44 Member Posts: 10
    I have to write it in assembly language
    would you please guide me to do this?
    i can't to 6,7
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : I have to write it in assembly language
    : would you please guide me to do this?
    : i can't to 6,7
    :

    [color=Red]EDIT: Hmm.. the formatting of the code blocks is utterly evil - I can't seem to get it fixed though[/color]

    6 and 7 heavily depend on the environment. What is the interface? Is it a console application? If so, it would help to know the functions available to interface with the screen. There might be a clear screen function, but chances are you'll have to implement it yourself by writing the display area full with spaces.

    At the very least, you'll need a variable to store the amount of printed texts to the screen. Again, a question arises: what is the output format of the assembly code? If it's an executable format, you could declare this variable in the Data section. For flat binary files, any location will do (as long as you make sure that piece of the binary doesn't get executed).

    I'll just assume for now you have a printing function defined as:
    [code]
    void print(char* szText, int x, int y, char color)
    [/code]
    Following the cdecl calling convention (arguments are pushed right-to-left and the caller pops the stack afterwards).
    Also, I'll assume color is a byte in the form 0000IRGB (where I stands for Intensity, and RGB for red/green/blue)

    [code]
    ; Use the amount of displayed as a color
    mov eax, [varDisplayed]
    inc eax ;Start with blue
    push eax ;Push Argumentcolor
    ; Get a random y position
    call _GetMaxY
    mov ecx, eax
    push ecx
    call _rand
    pop ecx
    xor edx, edx
    div ecx
    push edx ;Push ArgumentY: rand() % GetMaxY
    ; Same code here only then using GetMaxX
    ...
    ; Now push the word to print
    ; The word was chosen in one of the previous steps
    ; The following line should be modified depending on
    ; how it is stored. The line right now works for a variable
    ; holding the address of the word in memory
    push dword [chosenWord]
    call _print ;Print word using push'd parameters
    pop eax ;Remove parameters from the stack
    pop eax
    pop eax
    pop eax
    ; Increment printed word counter
    inc dword [varDisplayed]
    cmp dword [varDisplayed], 10
    jb Done
    ; Clear screen (however this is done... This assumes a clrscr function)
    mov dword [varDisplayed], 0
    call _clrscr
    Done:
    [/code]

    Well... something like this (haven't tested it). Ofcourse, since I have NO IDEA what environment you are using this might not even work. On top of that, it's NASM syntax and if you are using AT&T syntax it'll be near unreadable to you.
    Anyway, let me know if this helped at all.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • palm44palm44 Member Posts: 10
    thank you very much
    but i have some question
    : push dword [chosenWord]
    how can i get word from data?
    i already declare 100 vocabularies
    and how to random it??

    in 5.Randomly get one vocabulary from database above.
    how can i do this
    i'm so confuse about it.

    thanks for your concern
    :)
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : thank you very much
    : but i have some question
    : : push dword [chosenWord]
    : how can i get word from data?
    : i already declare 100 vocabularies
    : and how to random it??
    :
    : in 5.Randomly get one vocabulary from database above.
    : how can i do this
    : i'm so confuse about it.
    :
    : thanks for your concern
    : :)
    :

    Could you show me your code? It would greatly help.
    To randomize, use the rand()%100 trick:
    [code]
    call _rand
    xor edx, edx
    mov ecx, 100
    div ecx
    mov edx, eax
    ; EAX contains the index (0-99) of the random word
    [/code]

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • palm44palm44 Member Posts: 10
    : Could you show me your code? It would greatly help.
    : To randomize, use the rand()%100 trick:
    : [code]:
    : call _rand
    : xor edx, edx
    : mov ecx, 100
    : div ecx
    : mov edx, eax
    : ; EAX contains the index (0-99) of the random word

    thank you very much
    but i confuse that why eax contain index???
    it doesn't esi or edi ??

    THANKS FOR YOUR CONCERN
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : : Could you show me your code? It would greatly help.
    : : To randomize, use the rand()%100 trick:
    : : [code]: :
    : : call _rand
    : : xor edx, edx
    : : mov ecx, 100
    : : div ecx
    : : mov edx, eax
    : : ; EAX contains the index (0-99) of the random word
    : [/code]
    : thank you very much
    : but i confuse that why eax contain index???
    : it doesn't esi or edi ??
    :

    Basically, EAX contains the index because I say it does :)
    EAX contains a 32 bits number, just as ESI or EDI. The only thing that makes ESI or EDI different from EAX is its usage in certain instructions (like the lodsx instructions). But essentially there is no difference and even in adressing EAX has the same usages as ESI or EDI.
    In this case, with Index I mean the entry number into the vocabulary, just like a variable in C could be used for that.
    [code]
    //C-style vocabulary array:
    char* vocabulary[100] = {...};

    ; Then you calculate EAX as shown above
    ...
    ; Now the reason why I call it 'Index' becomes clear:
    ; vocabulary will be compiled as an address - a flat number
    ; This will be the base. Then we use eax as an index into the
    ; array, and each item uses 4 bytes (standard pointer size)
    mov esi, [vocabulary + 4*eax]
    ; ESI now points to the first character of the randomly
    ; selected vocabulary word
    [/code]

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • palm44palm44 Member Posts: 10
    so can i declare vocabulary like this
    ex. vocab BYTE "ant","apple",0

    and then in my idea
    can i do like this
    mov esi,OFFSET vocab

    so if i want to random.
    can i do like this

    mov eax,LENGTHOF vocab-1
    Call RandomRange

    so what should i do next???
    i how can i get the random number??
    where is it?? eax?? or what??

    THANKS FOR YOUR CONCERN
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : so can i declare vocabulary like this
    : ex. vocab BYTE "ant","apple",0
    :
    : and then in my idea
    : can i do like this
    : mov esi,OFFSET vocab
    :
    : so if i want to random.
    : can i do like this
    :
    : mov eax,LENGTHOF vocab-1
    : Call RandomRange
    :
    : so what should i do next???
    : i how can i get the random number??
    : where is it?? eax?? or what??
    :
    : THANKS FOR YOUR CONCERN
    :

    The essence of assembler is that everything is where you want it to be.

    If, however, you are following any C calling conventions then the return value is always in EAX. However, those calling conventions also dicatate that one preserves certain registers... you'll have to be careful to do so if you are using it.
    My own calling convention for when I program purely in assembly is to preserve every register except for EAX - but only when it is used to return a value.

    Here's an C-compatible assembly example of how such would be done.

    The following code uses NASM preprocessor directives so you don't have to type something a 100 times
    [code]
    SECTION .data
    ; Create the word pointer array (char* vocabulary[] = {...})
    vocabulary:
    %assign i 1
    %rep 100
    dd voc %+ i
    %assign i i+1
    %endrep

    ; Unfortunately, the 100 words still need to be inputted here:
    voc1 db "Hello", 0
    voc2 db "Word2", 0
    voc3 db "Something else", 0
    ...

    SECTION .text
    ; Here's a [b]part[/b] of the code - we first get the random index (0-99)
    call _rand
    xor edx, edx
    mov ecx, 100
    div ecx
    ; We'll store the address of the word in ESI (now using EDX for the index)
    ; Now that we're starting to think about calling conventions we'll
    ; preserve the ESI register too
    push esi
    mov esi, [vocabulary + 4*edx]
    ; ESI points to the word
    ; Furtherly, it's just a matter of passing this parameter to a print
    ; function, fr example: _cputs
    push esi
    call __cputs
    pop esi
    pop esi ;Restore ESI register to what it was
    [/code]

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • palm44palm44 Member Posts: 10
    : : so can i declare vocabulary like this
    : : ex. vocab BYTE "ant","apple",0
    : :
    : : and then in my idea
    : : can i do like this
    : : mov esi,OFFSET vocab
    : :
    : : so if i want to random.
    : : can i do like this
    : :
    : : mov eax,LENGTHOF vocab-1
    : : Call RandomRange
    : :
    : : so what should i do next???
    : : i how can i get the random number??
    : : where is it?? eax?? or what??
    : :
    : : THANKS FOR YOUR CONCERN
    : :
    :
    : The essence of assembler is that everything is where you want it to
    : be.
    :
    : If, however, you are following any C calling conventions then the
    : return value is always in EAX. However, those calling conventions
    : also dicatate that one preserves certain registers... you'll have to
    : be careful to do so if you are using it.
    : My own calling convention for when I program purely in assembly is
    : to preserve every register except for EAX - but only when it is used
    : to return a value.
    :
    : Here's an C-compatible assembly example of how such would be done.
    :
    : The following code uses NASM preprocessor directives so you don't
    : have to type something a 100 times
    : [code]:
    : SECTION .data
    : ; Create the word pointer array (char* vocabulary[] = {...})
    : vocabulary:
    : %assign i 1
    : %rep 100
    : dd voc %+ i
    : %assign i i+1
    : %endrep
    :
    : ; Unfortunately, the 100 words still need to be inputted here:
    : voc1 db "Hello", 0
    : voc2 db "Word2", 0
    : voc3 db "Something else", 0
    : ...
    :
    : SECTION .text
    : ; Here's a [b]part[/b] of the code - we first get the random index (0-99)
    : call _rand
    : xor edx, edx
    : mov ecx, 100
    : div ecx
    : ; We'll store the address of the word in ESI (now using EDX for the index)
    : ; Now that we're starting to think about calling conventions we'll
    : ; preserve the ESI register too
    : push esi
    : mov esi, [vocabulary + 4*edx]
    : ; ESI points to the word
    : ; Furtherly, it's just a matter of passing this parameter to a print
    : ; function, fr example: _cputs
    : push esi
    : call __cputs
    : pop esi
    : pop esi ;Restore ESI register to what it was
    : [/code]:
    :
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry


    sorry again Sir,but i don't understand it

    : push esi
    : mov esi, [vocabulary + 4*edx]

    when random,is it keep in edx??? not eax ????
    would u please write about 3,5,6 for me??
    thank you very much
«1
Sign In or Register to comment.