flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > 'out' macro Goto page 1, 2 Next |
Author |
|
revolution 30 Oct 2006, 12:18
ManOfSteel wrote: if it can be optimized Code: if (data and 0xffffffffffffff00) = 0 ;byte ;.. elseif (data and 0xffffffffffff0000) = 0 ;word ;.. elseif (data and 0xffffffff00000000) = 0 ;dword ;.. else ;qword ;.. end if ManOfSteel wrote: if I do a 'out 0x60,al', I will get an 'error: invalid value'. Why is that? Code: if 0x60 < 256 & al < 256 |
|||
30 Oct 2006, 12:18 |
|
Tomasz Grysztar 30 Oct 2006, 13:08
What if you want to send 16-bit value like 0000h?
|
|||
30 Oct 2006, 13:08 |
|
vid 30 Oct 2006, 13:26
i suggest syntax like:
Code: out 14h, byte 18 out 14h, word 0 and use "match" to check type and later Code: out 14h, <"abcd", 13,10, "aa"> |
|||
30 Oct 2006, 13:26 |
|
ManOfSteel 31 Oct 2006, 07:19
revolution,
Quote: You need to check if the input parameter "data" is "al" before you try to use the parameter with a numeric comparison operator. Well, that's the point! How can I do that? How can I detect if 'data' is a register or an immediate value. Tomasz Grysztar, Quote: What if you want to send 16-bit value like 0000h? As I said, it supports the six types of 'out' shown in Intel manuals (port8/data8, port8/data16, port8/data32, port16/data8, port16/data16, port16/data32). I did not post them all, because it is not the goal of the thread (and it is easy to complete, anyway). My only problem is that it does not accept registers. |
|||
31 Oct 2006, 07:19 |
|
revolution 31 Oct 2006, 10:41
ManOfSteel wrote: Well, that's the point! How can I do that? How can I detect if 'data' is a register or an immediate value. vid wrote: and use "match" to check type |
|||
31 Oct 2006, 10:41 |
|
vid 31 Oct 2006, 11:44
Quote: How can I detect if 'data' is a register or an immediate value. assembly time "if" directive: Code: macro jesus arg { if arg in <al, bl, cl, dl, ah, dh, ch, dh> ;8bit register else if arg in <ax, bx, cx, dx, bp, sp, si, di> ;16bit register else if arg in <eax, ebx, ecx, edx, ebp, esp, esi, edi> ;32bit register end if } |
|||
31 Oct 2006, 11:44 |
|
Tomasz Grysztar 01 Nov 2006, 18:16
ManOfSteel wrote:
Perhaps you misunderstood. I was refering to the fact, that you detect 16-bit value by checking whether it is larger than 255 and smaller than 65536. However you may still need to send a 16-bit value smaller than 256. Thus the vid's suggestion to use syntax like "byte ..."/"word ...". |
|||
01 Nov 2006, 18:16 |
|
ManOfSteel 02 Nov 2006, 07:25
Hello,
now it does six 'if' to know whether the data is in the accumulator and the port is within the right boundaries and then six other 'if' to know if both the port and the data are within the right boundaries (when working with immediate values only). In the first six 'if', I have removed the 'mov {register},data' so there is no redundance. The code is quite long now, but it does what it is supposed to do. It works with any of these: Code: out 0x60,al out 0x60,ax out 0x60,eax out 0x512,al out 0x512,ax out 0x512,eax out 0x60,2 out 0x60,512 out 0x60,2097152 out 0x512,2 out 0x512,512 out 0x512,2097152 Just one more thing (by curiosity), could you tell me how could it have been done with the match directive. Tomasz Grysztar, I will do what was suggested by vid, but I have replaced all the out instructions by the macro and I have not encountered any problem (so far). The whole OS was perfectly assembled and runs happily. Thanks everyone for all the help! |
|||
02 Nov 2006, 07:25 |
|
ManOfSteel 03 Nov 2006, 11:53
Nay! I cannot figure this out. I tried to do it like vid said, but I am not getting any positive results. I really need some deeper explanation with this one (match directive used to detect parameter size). A small piece of code about "match" would be perfect.
|
|||
03 Nov 2006, 11:53 |
|
vid 03 Nov 2006, 13:00
Code: macro out port, val { match =byte val, val \{ mov al, val out port, al \} match =word val, val \{ mov al, val out port, al \} ... etc } this is just how match works, you need also to check for case when nothing matched and throw error, or try to use original "out" instruction: Code: macro out port, val { done equ 0 match =byte val, val \{ mov al, val out port, al done equ 1 \} match =word val, val \{ mov al, val out port, al done equ 1 \} match =0, done \{ out port, val \} ... etc } read manual about usage of match |
|||
03 Nov 2006, 13:00 |
|
ManOfSteel 04 Nov 2006, 21:55
How is it supposed to work? Using for example 'out 10,45' does precisely nothing when I remove the last match and otherwise throws an 'invalid operand' error which is quite weird since it has the same syntax as the original 'out' instruction. Also, passing any random garbage will have the same result.
Quote:
I upgraded from fasm 1.66 yesterday thinking it was just a bug. Apparently it was not. There is something wrong or missing here. |
|||
04 Nov 2006, 21:55 |
|
vid 05 Nov 2006, 16:42
because you don't know if you want to pass byte 45, or word 45 (byte 45 and byte 0), or dword 45 (byte 45 and 3 bytes 0) etc...
i am also not sure about what can be OUT instruction's arguments. You cannot do "out 10, 45" directly? |
|||
05 Nov 2006, 16:42 |
|
Tomasz Grysztar 05 Nov 2006, 16:44
vid wrote: i am also not sure about what can be OUT instruction's arguments. You cannot do "out 10, 45" directly? http://flatassembler.net/docs.php?article=manual#2.1.7 |
|||
05 Nov 2006, 16:44 |
|
vid 05 Nov 2006, 16:50
i know, i'm just lazy
|
|||
05 Nov 2006, 16:50 |
|
Tomasz Grysztar 05 Nov 2006, 16:51
That's what I thought.
|
|||
05 Nov 2006, 16:51 |
|
vid 05 Nov 2006, 16:52
so, last match should be:
Code: match =0, done \{ mov al, val out port, al \} |
|||
05 Nov 2006, 16:52 |
|
ManOfSteel 07 Nov 2006, 09:08
Well, it still does not work, even with a 'byte' or 'word' before the value. And I think I realized why. It seems fasm thinks 'byte val' or 'word val' are two separate parameters.
I tried the following. Code: macro out port,val { done equ 0 match =byte val,val val \{ ;mov al,val ;out port,al done equ 1 display 'byte' \} match =word val,val val \{ ;mov al,val ;out port,al done equ 1 display 'word' \} match =0,done \{display 'error'\} } out 0x60,byte 10 It displays 'byte' when using 'byte 10' and 'word' when using 'word 10', but once I uncomment the actual 'out' instructions, it does not work anymore. Anyway, I have added a new parameter just for the size and reprogrammed the whole thing. Code: macro out port,size,data { ... if data in <al,ax,eax> & port < 256 ;port is a byte and data is in a register match = byte,size ;... match = word,size ;... match = dword,size ;etc else if port < 256 ;same as above when data is an immediate ;etc else if data in <al,ax,eax> & port > 255 ;same as above when port is a word and data is in a register ;etc else if port > 255 ;same as above when port is a word and data is an immediate ;etc end if ;... } It is used like this: out 0x60,dword,10 , and it works well. I think I am done with it this time, but of course if someone has any comment on the code or explanation on why it did not work with 'byte xxxx' and 'word xxxx', s/he is welcome. And thank you to everyone who helped me. |
|||
07 Nov 2006, 09:08 |
|
Tomasz Grysztar 07 Nov 2006, 09:28
The correct macro should be like:
Code: macro out port,val { done equ 0 match =byte v,val \{ mov al,v out port,al done equ 1 \} match =word v,val \{ mov ax,v out port,ax done equ 1 \} match =dword v,val \{ mov eax,v out port,eax done equ 1 \} match =0,done \{display 'error'\} } |
|||
07 Nov 2006, 09:28 |
|
dark_teo 14 Nov 2006, 23:09
how out (port,val)
for example: out (3f8h,byte 20h) out (bx,al) out (3f8h,bx) ???? |
|||
14 Nov 2006, 23:09 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.