Inefficiency of `mod'

Rugxulo rugxulo at
Tue Oct 26 01:15:02 CEST 2010


On 10/25/10, Maurice Lombardi <Maurice.Lombardi at> wrote:
> This means that GPC does an arithmetical right shift (i.e. propagating
> the 1 (or 0) in the leftmost (highest weight) position), while BP does a
> logical right shift.

Right, so GPC does it the same as C (no surprise, GCC-based).

> It seems more sound to use an arithmetical shift for integer and a
> logical shift for cardinal.

Right, so shifting a signed number should keep the sign. (Though
"cardinal" isn't standard Pascal, comes from Modula-2, and Wirth
removed it for Oberon).

Tell me if this helps demonstrate anything:

--- snip ---

CR equ 13
LF equ 10

org 100h

 mov eax,-2    ; = 0xFFFFFFFE
 shr eax,1
 call hexdword ; EAX = 0x7FFFFFFF
 call newline

 mov eax,-2
 sar eax,1
 call hexdword ; EAX = 0xFFFFFFFF
 call newline

 int 20h       ; exit

 mov ecx,8     ; 32/4
 rol eax,4
 push eax
 and al,0Fh
 cmp al,10
 sbb al,69h
 int 29h       ; putchar(AL)
 pop eax
 loop .begin

 mov al,CR
 int 29h
 mov al,LF
 int 29h

More information about the Gpc mailing list