From: T.M. Sommers on
Rod Pemberton wrote:
>
> Snipping the historical 1-7 as both you an T.M. Sommers did, also distorts
> my entire post... To which, it appears that five or six others who never
> read it responded...

I snipped it because it was irrelevant. It does not matter what
K&R said, or what PCC did. C is defined today by the standard.

--
Thomas M. Sommers -- tms(a)nj.net -- AB2SB


From: Frank Kotler on
Herbert Kleebauer wrote:
> Frank Kotler wrote:
>
>
>>I haven't figured out why the "direct to binary" version isn't working.
>
>
> Here a working version.

Thank you Herbert!!! Sorry for the delayed reply. Like the careless
butcher, I've gotten a little behind in my work...

> It's ugly,

Yes.

> but either NASM is missing some
> important features or I don't understand how to proper use NASM.

Possibly both?

> The nop's are in again so I could do a binary compare with the
> original binary.

Okay.

> ; nasm -O999 -f bin -o myprog myprog.asm

I found that "-O999" caught a couple of "optimization opportunities"
that you missed. Are you getting a good "binary compare"? "My version"
(not working - "broken pipe" - I *hate* it when that happens!) is a few
bytes smaller than the Lindela version, identical in size to your Nasm
version.

> %macro dc.b 2+

Wow! You went to the trouble to learn Nasm's macro systen!!! This is
similar in principle tho how Brian's "elf.inc" does it. I'm *trying* to
avoid that...

....
> ; don't remove the following line and use offs directly
> ; this seems to be a bug in NASM
> offs2 equ offs
> ;===========================================================================

I don't know what's going on here. Haven't experimented. I shall.

> @1 equ $08048000 ; virtual address of code start
> @@1 equ 0 ; file byte address of code start

Okay, using symbols like "@1", "@@1", "@2", "@@2", "@3" is not Nasm's
fault. People have different ideas of "beauty" and "beastliness", I
guess. *I* don't feel that this helps.

....
> ; you MUST NOT use db/dw/dd to define data, use dc.b/dc.w/dc.l instead

I *think* Nasm's got the ability to avoid this... I just can't get it to
*work*!

When you're digging yourself deeper and deeper into a whole, quit
digging. When you get lost, go back to something simple, and work up to
it again. In hopes that this may work, here's a simple test of Nasm's
supposed abilities. You want to be able to alter "org" or "$"... Nasm
doesn't do it that way. Mike Ter Louw's "multisection support" for "-f
bin" gives us "start", "vstart", "align", "valign", "follows",
"vfollows", etc. This should give us complete control over the placement
and alignment of sections, and allow us to separate the "virtual
address" from the physical file position.


[map all sectest.map]

bits 32
org 8048000h

section .text
dd FOO
dd BAR
dd BAZ

mov eax, foodat
mov eax, bardat
mov eax, bazdat
mov eax, z_end

foodat dd 42

FOO equ $ - $$

section .data valign=4096
bardat dd 43
misalign db 0

BAR equ $ - $$

section .bss vfollows=.data valign=1
bazdat resd 41
z_end resb 1

BAZ equ $ - $$

Here's the map file:


- NASM Map file
---------------------------------------------------------------

Source file: sectest.asm
Output file: sectest.bin

-- Program origin
-------------------------------------------------------------

08048000

-- Sections (summary)
---------------------------------------------------------

Vstart Start Stop Length Class Name
08048000 08048000 08048024 00000024 progbits .text
08049000 08048024 08048029 00000005 progbits .data
08049005 08049005 080490AA 000000A5 nobits .bss

-- Sections (detailed)
--------------------------------------------------------

---- Section .text
------------------------------------------------------------

class: progbits
length: 00000024
start: 08048000
align: not defined
follows: not defined
vstart: 08048000
valign: not defined
vfollows: not defined

---- Section .data
------------------------------------------------------------

class: progbits
length: 00000005
start: 08048024
align: 00000004
follows: not defined
vstart: 08049000
valign: 00001000
vfollows: not defined

---- Section .bss
-------------------------------------------------------------

class: nobits
length: 000000A5
start: 08049005
align: not defined
follows: not defined
vstart: 08049005
valign: 00000001
vfollows: .data

-- Symbols
--------------------------------------------------------------------

---- No Section
---------------------------------------------------------------

Value Name
00000024 FOO
00000005 BAR
000000A5 BAZ
00000024 FOO
00000005 BAR
000000A5 BAZ

(dunno why these are duplicated....)

---- Section .text
------------------------------------------------------------

Real Virtual Name
08048020 08048020 foodat

---- Section .data
------------------------------------------------------------

Real Virtual Name
08048024 08049000 bardat
08048028 08049004 misalign

---- Section .bss
-------------------------------------------------------------

Real Virtual Name
08049005 08049005 bazdat
080490A9 080490A9 z_end

And here's the disassembly:

08048000 2400 and al,0x0
08048002 0000 add [eax],al
08048004 05000000A5 add eax,0xa5000000
08048009 0000 add [eax],al
0804800B 00 db 0x00
0804800C B820800408 mov eax,0x8048020
08048011 B800900408 mov eax,0x8049000
08048016 B805900408 mov eax,0x8049005
0804801B B8A9900408 mov eax,0x80490a9
08048020 2A00 sub al,[eax]
08048022 0000 add [eax],al
08048024 2B00 sub eax,[eax]
08048026 0000 add [eax],al
08048028 00 db 0x00

Does this look like what I'm trying to do? I think it's doing what I
intend, but when I expand the same technique to the "full version", I'm
getting something subtly(?) wrong. Lemme go back to banging on it (I
really haven't spent much time with it since the initial "translation" -
lotsa distractions).

(~h)Later,
Frank
From: Herbert Kleebauer on
Frank Kotler wrote:
> Herbert Kleebauer wrote:

> > ; nasm -O999 -f bin -o myprog myprog.asm
>
> I found that "-O999" caught a couple of "optimization opportunities"
> that you missed.

Wouldn't say "missed", better "don't care". I always start with short
branches and change them to long branches if I get an error. But if
I rearrange the code I never check if I can convert a long branch
back to a short branch. And also for cmp/add/sub I often forget that
there is a short form.

> Are you getting a good "binary compare"?

After converting unnecessary long to short branches and using the short
form of add/sub/cmp I got identical binaries. This was surprising because
normally my encoding of reg,reg is the opposite way as other assemblers do.

> > %macro dc.b 2+
>
> Wow! You went to the trouble to learn Nasm's macro systen!!! This is
> similar in principle tho how Brian's "elf.inc" does it. I'm *trying* to
> avoid that...

Didn't see any other way. But maybe I should have read the NASM manual.


>
> > @1 equ $08048000 ; virtual address of code start
> > @@1 equ 0 ; file byte address of code start
>
> Okay, using symbols like "@1", "@@1", "@2", "@@2", "@3" is not Nasm's
> fault. People have different ideas of "beauty" and "beastliness", I
> guess. *I* don't feel that this helps.

In Lindela @ is the symbol for the current location counter ($ in NASM)
and @@ is the symbol for the output file position counter. And because
NASM doesn't allow a redefine of a symbol I had to add a number (@1, @2,..)



> I *think* Nasm's got the ability to avoid this... I just can't get it to
> *work*!

I got it to work now. But I must say it still was more try and error
than really understanding the logic behind NASM (must be something
the same way as the Intel syntax logic).

> bin" gives us "start", "vstart", "align", "valign", "follows",
> "vfollows", etc. This should give us complete control over the placement
> and alignment of sections, and allow us to separate the "virtual
> address" from the physical file position.

Maybe the documentation could be a little bit more clear. Anyhow,
here a working version:

;===========================================================================
; A simple graphics demo for Linux/X by Frank Kotler & ASCII Annie
; nasm -O999 -f bin -o myprog myprog.asm
;===========================================================================
orig equ $08048000

code_addr equ orig
code_offset equ 0
section .text vstart=code_addr
;===========================================================================

;--------------------------- ELF header -----------------------------------
dd $464c457f,$00010101,0,0,$00030002,1,main,$34,0,0,$00200034,2,0
dd 1,code_offset,code_addr,code_addr,code_filez,code_memsz,5,4096
dd 1,data_offset,data_addr,data_addr,data_filez,data_memsz,6,4096

;--------------------------- code ------------------------------------------
USE32
main: mov [stack_ptr], esp ; save initial stack pointer

; ******************** get socket handle ***************************
push 0 ; no protocol specified
push 1 ; 1: SOCK_STREAM (/usr/include/linux/net.h)
push 1 ; 1: AF_UNIX, AF_LOCAL (/usr/include/linux/socket.h)
mov ecx, esp ; pointer to parameter for "socket"
mov ebx, 1 ; "socket" (/usr/include/linux/net.h)
mov eax, 102 ; socketcall (/usr/include/asm/unistd.h)
int 80h
add esp, 3 * 4 ; free space for parameters
test eax, eax ; ERROR
js err

; my apologies for propagating this sloppiness.
; really should be "cmp eax, -4096" (or -4095?)
; won't happen here, but we *could* get a
; valid return over 2G! - fbk

mov [x_handle], eax

; ********** connect socket to /tmp/.X11-unix/X0" ******************
push sockaddr_un_l
push sockaddr_un ; (/usr/include/linux/un.h)
push dword [x_handle] ; socket handle
mov ecx, esp ; pointer to parameter for "connect"
mov ebx, 3 ; "connect" (/usr/include/linux/net.h)
mov eax, 102 ; socketcall (/usr/include/asm/unistd.h)
int 80h
add esp, 3 * 4 ; free space for parameters
test eax, eax ; ERROR
js err

; *************** make socket read non blocking *******************
mov ebx, [x_handle] ; socket handle
mov ecx, 3 ; F_GETFL (/usr/include/asm/fcntl.h)
mov eax, 55 ; fcntl (/usr/include/asm/unistd.h)
int 80h
test eax, eax ; ERROR
js err
mov ebx, [x_handle] ; socket handle
mov ecx, 4 ; F_SETFL (/usr/include/asm/fcntl.h)
mov edx, eax
or edx, 800h ; O_NONBLOCK (/usr/include/asm/fcntl.h)
mov eax, 55 ; fcntl (/usr/include/asm/unistd.h)
int 80h
test eax, eax ; ERROR
js err

; ******************* send connect message *************************
mov eax, send1 ; pointer to connect message
mov edx, send1l

call get_xauth ; try to read .Xauthority
jc _11 ; no success, let's try without auth.

mov [send1+6], bx ; insert name length
mov [send1+8], si ; insert data length

call x_send ; send header

mov eax, ecx ; pointer to name
lea edx, [ebx + 3] ; pad to a multiple of 4
and edx, -4
call x_send ; send name

mov eax, ebp ; pointer to data
lea edx, [esi + 3] ; pad to a multiple of 4
and edx, -4
_11: call x_send ; send data

xor ebp, ebp ; number of total bytes read
mov esi, buf2 ; pointer to buffer for next read
mov edi, buf2l ; max. bytes to read

.10: mov eax, esi
mov edx, edi
call x_receive_raw
jz .10 ; but we need a reply

cmp byte [buf2], 1 ; success
jne err ; something went wrong

add ebp, eax ; total read bytes
add esi, eax ; pointer to buffer for next read
sub edi, eax ; max. bytes to read
cmp ebp, 8 ; at least 8 bytes read?
jc .10 ; no, get more

movzx ebx, word [buf2 + 6] ; additional data in 4 bytes
lea ebx, [ebx * 4 + 8] ; total size in bytes
cmp ebp, ebx ; all read
jc .10 ; no, get more

; ******************* calculate id's *******************************
mov esi, buf2
mov eax, [esi + 0Ch] ; resource_id_base

mov edx, [esi + 10h] ; resource_id_mask
mov ecx, edx
neg ecx
and edx, ecx ; resource_id_incr

mov [s2a], eax ; wid for CreateWindow
mov [s3a], eax ; wid for MapWindow
mov [s4a], eax ; wid for CreateDC
mov [s5a], eax ; wid for CreateDC
mov [s6a], eax ; wid for SetInputFocus

add eax, edx ; next id
mov [s4b], eax ; cid for CreateDC
mov [s5b], eax ; cid for CreateDC

add eax, edx ; next id ; lint!!!

; mov [resource_id_next], eax
; mov [resource_id_incr], edx

; ******************* get root window id ***************************
movzx eax, word [esi + 18h] ; length of vendor string
add eax, 28h + 3 ; const header length + round vendor length
and al, -4 ; round to 4 bytes

movzx edx, byte [esi + 1Dh] ; number of FORMATs
shl edx, 3 ; 8 byte for each FORMAT entry
add edx, eax ; offset to root WINDOW id

mov eax, [esi + edx] ; root window
mov [s2b], eax ; CreateWindow needs root window id

mov eax, [esi + edx + 20] ; width/height of root window
mov [s2x], eax ; create window full size

sub eax, (200 << 16) + 320
shr eax, 1
and eax, 0FFFF7FFFh
mov [s5x], eax ; center drawing

; ******************* send CreatWindow request *********************
mov eax, send2
mov edx, send2l
call x_send
call x_receive
jz .20 ; no message is a good message
cmp byte [eax], 0 ; error message
je ende

; ******************* send MapWindow request ***********************
.20: mov eax, send3
mov edx, send3l
call x_send
call x_receive
jz .30 ; no message is a good message
cmp byte [eax], 0 ; error message
je ende

; ******************* send CreatDC request *************************
.30: mov eax, send4
mov edx, send4l
call x_send
call x_receive
jz .40 ; no message is a good message
cmp byte [eax], 0 ; error message
je ende

; ******************* send SetInputFocust *************************
.40: mov eax, send6
mov edx, send6l
call x_send
call x_receive
jz .60 ; no message is a good message
cmp byte [eax], 0 ; error message
je ende

.60: call init_color ; init 64 VGA colors

; ******************** main loop ***************************
.50: call annie ; generate next picture
call display
call x_receive
jz .50 ; no message is a good message

cmp byte [eax], 0 ; error message
je err
cmp byte [eax], 2 ; key press
je ende
cmp byte [eax], 4 ; button press
jne .50
err:
ende: mov ebx, 0 ; return code
mov eax, 1 ; exit
int 80h

;------------------------------------------
display:
mov esi, screen
mov ecx, 20 ; we use 20 parts to make each less than 16k
..10
mov eax, send5
mov edx, send5l
call x_send
mov eax, esi
mov edx, 320 * 10 * 4 ; size of one part
call x_send
add word [s5y], 10 ; update y pos for next part
add esi, 320*10*4 ; update source pointer for next part
loop .10
sub word [s5y], 20*10 ; restore original y position
ret
;-----------------------------------------

; ********* Annie's code to draw a heart ****************
annie: pusha
xor ebx, ebx

.10: inc dword [annie1]
mov ecx, 320 * 200
xor edi, edi
.20: mov eax, edi ; byte pos in screen
xor edx, edx
mov ebx, 320 ; 320 lines
div ebx ; eax: line 0-199 edx: column 0-319
sub eax, 120 ; center y=120 (-120 .. +79)
sub edx, 160 ; x=160 (-160 .. +159)
jg .30
neg edx ; symmetric in x (0 .. 160)
.30: mov ebx, eax
imul ebx, ebx ; ebx = x*x
add eax, edx ; eax = x*x+y
imul eax ; eax = (x*x+y)**2 mod 2*16
add ebx, eax
jz .40
xor edx, edx
mov eax, 600000
div ebx
.40: add eax, [annie1] ; change color
shr al, 2
movzx eax, al
mov eax, [color+ eax * 4]
mov [screen + edi * 4], eax
inc edi
loop .20

popa
nop
ret

; ****************** initialize 64 VGA colors *********************
init_color:
pusha
mov esi, color
mov eax, 0 ; sic
mov ecx, 64
_01: mov [esi], eax
add esi, 4
add al, 10h
add ax, 800h
add eax, 40000h
loop _01
popa
nop
ret

;**********************************************************
;******** read cookie from $home/.Xauthority **************
;**********************************************************
; *
; input: stack_ptr: original sp at program start *
; output: C=0: cookie found in $home/.Xauthority *
; r2: pointer to protocol name *
; r3: length of protocol name *
; r4: pointer to protocol data *
; r5: length of protocol data *
; C=1: nothing found *
; r2/r3/r4/r5 undefined *
; *
; typedef struct xauth { *
; unsigned short family; *
; unsigned short address_length; *
; char *address; *
; unsigned short number_length; *
; char *number; *
; unsigned short name_length; *
; char *name; *
; unsigned short data_length; *
; char *data; *
; } Xauth; *
;**********************************************************

get_xauth:
push eax
push edx
push edi

mov edi, [stack_ptr] ; original stack pointer at program start
mov eax, [edi] ; number of arguments
lea edi, [edi + eax * 4 + 8] ; skip arguments + trailing null pointer

.20: mov esi, [edi] ; pointer to next env variable
add edi, 4
test esi, esi ; no more env variables
jz .notfound
cmp dword [esi], 'HOME' ; HOME found?
jne .20 ; no, try next
cmp byte [esi + 4], '=' ; HOME= found?
jne .20 ; no, try next
add esi, 5 ; start of HOME path
or ecx, -1
.30: inc ecx ; count length of HOME path
cmp byte [esi + ecx], 0
jne .30

or ecx, ecx ; at least one char long?
jz .notfound ; no, HOME is empty
cmp ecx, 256 ; more than 256 charcters
ja .notfound ; somebody tries a buffer overflow
mov edi, fname ; buffer for filename
rep movsb ; copy HOME path
mov eax, '/.Xa' ; 'aX./' ; add .Xauthority
stosd
mov eax, 'utho' ; 'ohtu'
stosd
mov eax, 'rity' ; 'ytir'
stosd
mov byte [edi], 0 ; and a trailing 0

mov ebx, fname
xor ecx, ecx ; readonly
mov eax, 5 ; open
int 80h

test eax, eax ; file open error?
js .notfound ; yes

mov ebx, eax ; file handle
mov ecx, buf2
mov edx, buf2l ; read 1024 byte
mov eax, 3 ; read
int 80h

cmp eax, buf2l
jnc err ; .Xauthority >= 1024 byte
mov ebp, eax ; bytes read

mov eax, 6 ; close
int 80h

test ebp, ebp ; file empty
jz .notfound

mov esi, buf2
add ebp, esi ; end of read data
xor eax, eax

.60: lodsw ; family
dec ax
jz .40 ; 1=FamilyLocal

mov ecx, 4 ; skip entry
.50: lodsw
ror ax, 8 ; big -> little endian
add esi, eax
loop .50
cmp esi, ebp ; more data
jc .60 ; try next entry

..notfound:
stc
jmp _70

.40: mov ecx, 2
mov ebx, ecx
.41: lodsw
ror ax, 8
add esi, eax ; skip address/number
loop .41

.42: lodsw
ror ax, 8
mov ecx, esi
mov ebx, eax
add esi, ebx

lodsw
ror ax, 8
mov ebp, esi
mov esi, eax
clc
_70: pop edi
pop edx
pop eax
ret

;**********************************************************
;******** send message to X server **************
;**********************************************************
; input: eax: pointer to message *
; edx: length of message *
;**********************************************************
x_send: pusha
mov ebp, eax ; pointer to next byte of message
mov esi, edx ; remaining bytes to send

.20: push 0 ; flags
push esi ; length
push ebp ; pointer to data
push dword [x_handle] ; socket handle
mov ecx, esp ; pointer to parameter for "send"
mov ebx, 9 ; "send" (/usr/include/linux/net.h)
mov eax, 102 ; socketcall (/usr/include/asm/unistd.h)
int 80h
add esp, 4*4 ; free space for parameters

cmp eax, -11 ; EAGAIN:
je .20 ; message couldn't be sent, try again

test eax, eax ; ERROR
js err

sub esi, eax ; remaining bytes to send
jz .30 ; nothing, all sent
add ebp, eax ; pointer to remaining message
jmp .20 ; send rest of message

.30: popa
nop
ret

;**********************************************************
;******** receive ONE message from X server **********
;**********************************************************
; input: none *
; output: Z=1: no complete message available *
; eax/edx undefined *
; Z=0: eax: pointer to message data *
; edx: size of data *
;**********************************************************
x_receive:
push ecx
push esi
push edi
_00: mov eax, [buf2_rest] ; still something in read buffer?
cmp eax, 32 ; a message has at least 32 bytes
jnc .10 ; maybe it is a complete message

.30: mov esi, [buf2_ptr] ; start of message
mov edi, buf2 ; start of buffer
mov [buf2_ptr], edi ; we copy message to top of buffer
cmp edi, esi ; already at top of buffer
je .50 ; then nothing to copy
or eax, eax ; nothing in buffer
jz .50 ; then also nothing to copy
mov ecx, eax ; copy to top of buffer
rep movsb

.50: mov edx, buf2l ; let's try to get some more data
sub edx, eax ; not more bytes than space is left in the buf
lea eax, [buf2 + eax] ; append it here
call x_receive_raw
jnz .20 ; we could read something
jmp _100 ; return with Z=1

.20: add [buf2_rest], eax ; now we have a few more bytes in the buffer
jmp _00 ; let's try again

.10: mov esi, [buf2_ptr] ; let's test if it is a complete meesage
cmp byte [esi], 34
ja err ; the last known message is nr 34
mov edx, 32
; cmp byte [esi], 0 ; error message
; je .40
cmp byte [esi], 1 ; reply message
jne .40 ; event message is always 32 byte
add edx, [esi + 12] ; + additional data for reply
add edx, [esi + 12] ; + additional data for reply
add edx, [esi + 12] ; + additional data for reply
add edx, [esi + 12] ; + additional data for reply
cmp eax, edx ; complete reply in buffer
jc .30 ; no, let's try to get more
.40: mov eax, esi ; pointer to data
sub [buf2_rest], edx ; new rest
add [buf2_ptr], edx ; pointer to next data; clear Z flag
_100: pop edi
pop esi
pop ecx
ret

;**********************************************************
;******** read data from X server **********
;**********************************************************
; input: eax: pointer to read buffer *
; edx: size of buffer *
; output: Z=1: nothing to read *
; Z=0: eax bytes read *
;**********************************************************
x_receive_raw:
push ecx
push ebx

push 0 ; flags
push edx ; bytes to read
push eax ; pointer to buffer
push dword [x_handle] ; socket handle
mov ecx, esp ; pointer to parameter for "recv"
mov ebx, 10 ; "recv" (/usr/include/linux/net.h)
mov eax, 102 ; socketcall (/usr/include/asm/unistd.h)
int 80h
add esp, 4 * 4 ; free space for parameters
pop ebx
pop ecx
cmp eax, -11 ; EAGAIN: no message available -> Z=1
je .10
test eax, eax ; <0: ERROR 0: NULL message -> Z=1
js err
.10: ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;--------------------------- constant data ---------------------------------
; (note that we're in .text, not .rdata)

align 4

sockaddr_un:
dw 1 ; 1: AF_UNIX, AF_LOCAL (/usr/include/linux/socket.h)
db "/tmp/.X11-unix/X0"
sockaddr_un_l equ $ - sockaddr_un


;---------------------------------------------------------------------------
;---------------------------------------------------------------------------

;===========================================================================
; end of code and constant data section
;===========================================================================
align 4
code_memsz equ $-$$
code_filez equ code_memsz

data_addr equ (orig+code_memsz+4095)/4096*4096 + (code_filez % 4096)
data_offset equ code_filez
section .data vstart=data_addr
;===========================================================================


;--------------------------- initialized data ------------------------------
buf2_ptr: dd buf2
buf2_rest: dd 0

; Connection Setup
send1: db $6c,0 ; LSB first
dw 11,0 ; major/minor version
dw 0,0 ; length of protocol name/data
dw 0 ; unused
send1l equ $ - send1

; Create Window
send2: db 1 ; opcode for Create Window
db 0 ; depth from parent
dw send2l/4; request length
s2a: dd 0 ; wid (has to be calculated)
s2b: dd 0 ; parent (has to be calculated)
dw 0 ; x
dw 0 ; y
s2x: dw 640 ; width
s2y: dw 400 ; heigth
dw 0 ; border-width
dw 0 ; class: CopyFromParent
dd 0 ; visual: CopyFromParent
dd 0A02h ; value-mask: background-pixel 2
; + override-redirect 200
; + event-mask 800
dd 0 ; background: black
db 1 ; override-redirect = true
db 0,0,0 ; pad
dd 5 ; event_mask: KeyPress 1
; +ButtenPress 4
; +PointerMotion 40
send2l equ (($-send2)+3) & 0fffffffch

; Map Window
send3: db 8 ; opcode for Map Window
db 0 ; unused
dw send3l/4; request length
s3a: dd 0 ; wid (has to be calculated)
send3l equ $ - send3

; Create GC
send4: db 55 ; opcode for CreateGC
db 0 ; unused
dw send4l/4; request length
s4b: dd 0 ; cid (has to be calculated)
s4a: dd 0 ; wid (has to be calculated)
dd 1+4+8 ; function+foreground+background
dd 3 ; function=copy
dd 0ffffffh ; foreground: white
dd 0080ffh ; background: light blue
send4l equ $ - send4

; Put Image
send5: db 72 ; opcode for PutImage
db 2 ; ZPixmap
dw send5l/4 + 320*10*4/4 ; request length
s5a: dd 0 ; wid (has to be calculated)
s5b: dd 0 ; cid (has to be calculated)
dw 320 ; width
dw 200/20 ; height
s5x: dw 0 ; dest-x
s5y: dw 0 ; dest-y
db 0 ; left-pad
db 24 ; depth
dw 0 ; unused
send5l equ $ - send5

; Set Input Focus
send6: db 42 ; opcode for SetInputFocus
db 0 ; revert-to None
dw send6l/4; request length
s6a: dd 0 ; wid (has to be calculated)
dd 0 ; timestamp CurrentTime
send6l equ $ - send6

;===========================================================================
idat_memsz equ $-$$

bss_addr equ data_addr+ ($-$$)
section .bss vstart=bss_addr
;===========================================================================

;--------------------------- uninitialized data ----------------------------

screen: resd 320*200 ; bitmap

stack_ptr: resd 1
x_handle: resd 1
annie1: resd 1
color: resd 64
fname: resb 256+32
buf2: resb 1024
buf2l equ $ - buf2

;---------------------------------------------------------------------------

;===========================================================================
udat_memsz equ $-$$
data_memsz equ idat_memsz + udat_memsz
data_filez equ idat_memsz
;===========================================================================
From: Rod Pemberton on

"Phil Carmody" <thefatphil_demunged(a)yahoo.co.uk> wrote in message
news:873aze5gms.fsf(a)nonospaz.fatphil.org...
> Well, it does say that ``la[--i]'' is to be evaluated before
``la[--i]=i''.

True, that is stated.

> It also says that ``--i'' is to be evalutate before ``la[--i]''.

False, that is unstated. But, it is a logical corollary to 'la[--i]' being
evaluated.

> That much I evidently have no issue with.
>
> It does *not* say that ``la[--i]'' is to be evaluated before ``i''.
>

True, that is unstated. But, if it where stated, that would contradict
conditions of 'la[--i]' being evaluated prior to 'la[--i]=i'.


It says 'la[--i]' is to be evaluated before 'la[--i]=i'. I.e., '--i' must
be evaluated prior to 'i' to maintain precedence:

7. Expressions
"The precedence of expression operators is the same as the order of the
major subsections of this section (highest
precedence first). ... Otherwise the order of evaluation of expressions is
undefined. In particular the compiler considers itself free to
compute subexpressions in the order it believes most efficient, even if the
subexpressions involve side effects."

7.1.5
"A primary expression followed by an expression in square brackets is a
primary expression."...

7.14.1 lvalue = expression
"The value of the expression replaces that of the object referred to by the
lvalue."...




Rod Pemberton

From: Phil Carmody on
"Rod Pemberton" <do_not_have(a)nowhere.cmm> writes:
> "Phil Carmody" <thefatphil_demunged(a)yahoo.co.uk> wrote in message
> news:873aze5gms.fsf(a)nonospaz.fatphil.org...
> > Well, it does say that ``la[--i]'' is to be evaluated before
> ``la[--i]=i''.
>
> True, that is stated.
>
> > It also says that ``--i'' is to be evalutate before ``la[--i]''.
>
> False, that is unstated. But, it is a logical corollary to 'la[--i]' being
> evaluated.
>
> > That much I evidently have no issue with.
> >
> > It does *not* say that ``la[--i]'' is to be evaluated before ``i''.
> >
>
> True, that is unstated. But, if it where stated, that would contradict
> conditions of 'la[--i]' being evaluated prior to 'la[--i]=i'.
>
>
> It says 'la[--i]' is to be evaluated before 'la[--i]=i'. I.e., '--i' must
> be evaluated prior to 'i' to maintain precedence:

Utter utter nonsense. Your "i.e." contains no valid logic at all.

> 7. Expressions
> "The precedence of expression operators is the same as the order of the
> major subsections of this section (highest
> precedence first). ... Otherwise the order of evaluation of expressions is
> undefined. In particular the compiler considers itself free to
> compute subexpressions in the order it believes most efficient, even if the
> subexpressions involve side effects."
>
> 7.1.5
> "A primary expression followed by an expression in square brackets is a
> primary expression."...

And?

> 7.14.1 lvalue = expression
> "The value of the expression replaces that of the object referred to by the
> lvalue."...

And?

I'm failing to see the "`lvalue' is evaluated before 'expression'"
in the above. If it said that, you'd have a point. It doesn't, for
a reason, and you don't, for a reason too.

The only thing relevant in the above is the fact that it clearly
says that where orders aren't specified otherwise, then they
undefined, which blows your whole argument out of the water.

And you've not worked out my teaser yet either I notice.

Phil
--
"Home taping is killing big business profits. We left this side blank
so you can help." -- Dead Kennedys, written upon the B-side of tapes of
/In God We Trust, Inc./.
First  |  Prev  |  Next  |  Last
Pages: 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Prev: masm linking from console
Next: NASM HelloWorld - DOS