Click to See Complete Forum and Search --> : I need help to do a calc in TASM
NoneOfThem
March 27th, 2009, 08:01 AM
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!
rxbagain
March 27th, 2009, 09:40 AM
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?
NoneOfThem
March 31st, 2009, 06:24 AM
VariableX db 0
VariableY db 0
They are not used for any kind of array, and 32 bit processor.
Thanks for all
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?
rxbagain
March 31st, 2009, 02:04 PM
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)
; 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
NoneOfThem
April 6th, 2009, 07:58 AM
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!!!!
rxbagain
April 6th, 2009, 10:48 AM
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.
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).
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"
cmp byte ptr [VariableX], 7
jle <label after the assignment and subtraction>
NoneOfThem
April 10th, 2009, 06:28 AM
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!!
rxbagain
April 10th, 2009, 07:58 PM
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.
NoneOfThem
April 14th, 2009, 10:27 AM
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?
rxbagain
April 14th, 2009, 07:38 PM
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
.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
NoneOfThem
April 15th, 2009, 02:42 AM
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.
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.