-
March 27th, 2009, 07:01 AM
#1
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!
-
March 27th, 2009, 08:40 AM
#2
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?
-
March 31st, 2009, 05:24 AM
#3
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
Originally Posted by rxbagain
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?
-
March 31st, 2009, 01:04 PM
#4
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
-
April 6th, 2009, 06:58 AM
#5
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!!!!
-
April 6th, 2009, 09:48 AM
#6
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>
-
April 10th, 2009, 05:28 AM
#7
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!!
-
April 10th, 2009, 06:58 PM
#8
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.
-
April 14th, 2009, 09:27 AM
#9
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?
-
April 14th, 2009, 06:38 PM
#10
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
-
April 15th, 2009, 01:42 AM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|