CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Mar 2009
    Posts
    28

    Question I need help to do a calc in TASM

    Hi friends!!!!

    I need helps to do this calc in TASM:

    SI=([VariableX-7]*4 + [VariableY-31])/2

    I'm beginner and I tried to do it but it is so difficult for my level.

    Thanks!

  2. #2
    Join Date
    Apr 2003
    Posts
    1,755

    Re: I need help to do a calc in TASM

    What kind of variables are VariableX and VariableY? The square bracket should imply array but the indexer is negative so i'm not sure.

    Also, what kind of number are you dealing with? Is it integer, single, double or what? Is it for 16bit or 32 bit processor?

  3. #3
    Join Date
    Mar 2009
    Posts
    28

    Re: I need help to do a calc in TASM

    VariableX db 0
    VariableY db 0

    They are not used for any kind of array, and 32 bit processor.

    Thanks for all



    Quote Originally Posted by rxbagain View Post
    What kind of variables are VariableX and VariableY? The square bracket should imply array but the indexer is negative so i'm not sure.

    Also, what kind of number are you dealing with? Is it integer, single, double or what? Is it for 16bit or 32 bit processor?

  4. #4
    Join Date
    Apr 2003
    Posts
    1,755

    Re: I need help to do a calc in TASM

    I'm not sure if you are really doing 32 bit assembly, you might be talking about your system's processor not the assembly code's target processor.

    I'll just present you with code that deals with signed numbers as I don't know if you are dealing with signed or unsigned. The result will be placed in AX register (signed number)
    Code:
          ; VariableX-7 * 4
          xor ax, ax
          mov al, [VariableX]     ; get VariableX
          sub al, 7               ; subtract 7
          cbw                     ; extend the register to 16 bit keeping the sign bit
          mov cx, 4
          imul cx                 ; multiply it with 4 (signed)
          mov cx, ax              ; store it temporarily to cx
    
          ; + (VariableY-31)
          xor ax, ax
          mov al, [VariableY]     ; get VariableY
          sub al, 31              ; subtract 7
          cbw                     ; extend the register to 16 bit keeping the sign bit
    
          ; we have now the values in cx and ax so we add them
          add ax, cx
    
          ; we finaly divide the result with 2
          ; a simple division by 2 can be done in SHR (unsigned) or SAR (signed)
          sar ax, 1

  5. #5
    Join Date
    Mar 2009
    Posts
    28

    Re: I need help to do a calc in TASM

    Hi friend!

    Thaks for type the code; but I have a little problem, the result can't be negative. I mean for example: if variableX= 0 0 - 7 = 0 not 0 - 7 = -7


    Thanks!!!!

  6. #6
    Join Date
    Apr 2003
    Posts
    1,755

    Re: I need help to do a calc in TASM

    You can do 3 things to make the negative as 0.

    1. Simply compare the result of subtraction. If it is less than 0 (negative), then make it zero.
    Code:
    cmp al, 0
    jge NUMBER_OK
    xor al, al
    NUMBER_OK:
    2. you can check the CARRY flag immediately after the subtraction. If it is set, it means a borrow 1 occurred (meaning negative result).
    Code:
    jnc NUMBER_OK
    xor al, al
    NUMBER_OK:
    3. Check the value before subtraction the 7 or 31. If VariableX/VariableY is less than ot equal to 7/31, just leave the values as 0 (as initially set by "xor ax, ax"
    Code:
    cmp byte ptr [VariableX], 7
    jle <label after the assignment and subtraction>

  7. #7
    Join Date
    Mar 2009
    Posts
    28

    Re: I need help to do a calc in TASM

    Hi,

    The code it's ok, but my instructor tell me that when the variables enter on a subrritune they must value 7 and 31. Can I send you all code in a asm file to you e-mail? Thnak you!!

  8. #8
    Join Date
    Apr 2003
    Posts
    1,755

    Re: I need help to do a calc in TASM

    Do you mean the variables should be validated before calling the function? Then simply place the validation in the code before you call your function and set to 7 or 31 if less than those values.

  9. #9
    Join Date
    Mar 2009
    Posts
    28

    Re: I need help to do a calc in TASM

    Hi friend, my little program works. Now I want to change any atribute and I want put blink text. I use this:

    mov bh, 0 ;page atribute
    mov bl, 10000111b ;colour atribute

    Doesn't work. It is correct?

  10. #10
    Join Date
    Apr 2003
    Posts
    1,755

    Re: I need help to do a calc in TASM

    If you are using windows, the text will not blink unless your console is in full screen mode and you need to reset the video mode. You can not see the blink effect if the console is in normal mode. It will also remove the blink effect when you switch from full-screen to normal mode and back to full-screen mode.

    Here's the code that resets video mode and prints a letter that blinks. Make sure the console is in full-screen mode before running
    Code:
    .8086
    .model small
    .stack 100h
    
    .code
    .startup
    
        mov ax, 0003h         ; set video mode 3 (80x25)
        int 10h
    
        mov ah, 09h           ; print char and attrib at cursor position
        mov al, 'X'           ; character to print
        mov bh, 0             ; page 0
        mov bl, 10000111b     ; blink attribute
        mov cx, 1             ; number of times to print the char
        int 10h               ; call video interrupt
            
    .exit
    end

  11. #11
    Join Date
    Mar 2009
    Posts
    28

    Re: I need help to do a calc in TASM

    Thanks my friend!

    I tried to risize the window console and imediatly I saw to use the blink mode I need the full screen but I don't know that could be necessary check before the video mode.

    See you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured