[list -] %INCLUDE "Along32.inc" %INCLUDE "Macros_Along.inc" [list +] ;--------------------------------------------------------------------- extern BitwiseMultiply ; HLL prototype: ; uint BitwiseMultiply(uint *multiplicand, uint *multiplier); ; Receives pointers to two unsigned 32-bit integers. ; Determines the product of the two integers using the bitwise ; multiplication method. Returns the product in the EAX register. ; Receives: EAX = address of multiplicand ; EBX = address of multiplier ; Returns: EAX = product of multiplicand and multiplier ;--------------------------------------------------------------------- ;--------------------------------------------------------------------- global PrintInt:function ; HLL prototype: ; void PrintInt(uint number); ; Prints number in a right-justified field of width 10 ; Receives: EAX = number ; Returns: Nothing ;--------------------------------------------------------------------- SECTION .data hrule times 44 db ('-') db 10,0 spacer1 times 2 db ' ' db 0 spacer2 times 4 db ' ' db 0 title times 11 db ' ' db 'BITWISE MULTIPLICATION',10,0 header times 2 db ' ' db 'Multiplicand' times 4 db ' ' db 'Multiplier' times 4 db ' ' db ' Product',10,0 SECTION .bss h resd 1 multiplicand resd 1 multiplier resd 1 SECTION .text global _start _start: finit ; initialize floating-point unit call ReadDec ; read an unsigned integer mov [h],eax ; move the integer to h mov edx,title ; write title call WriteString mov edx,hrule ; write hrule call WriteString mov edx,header ; write headings call WriteString mov edx,hrule ; write hrule call WriteString .L0: cmp dword [h],0 ; while h > 0 do jle .L1 mov edx,spacer1 call WriteString call ReadDec ; read an unsigned int mov [multiplicand],eax ; store in multiplicand mov al,' ' call WriteChar mov eax,[multiplicand] call PrintInt ; write multiplicand to stdout mov al,' ' call WriteChar mov edx,spacer2 call WriteString call ReadDec ; read an unsigned int mov [multiplier],eax ; store in multiplier call PrintInt ; write multiplier to stdout mov edx,spacer2 call WriteString mov eax,multiplicand ; &multiplicand in eax mov ebx,multiplier ; &multiplier in ebx call BitwiseMultiply call PrintInt ; write product to stdout mov al,`\n` call WriteChar dec dword [h] ; decrement h jmp .L0 ; end while .L1: mov edx,hrule ; write hrule call WriteString Exit {0} PrintInt: SECTION .bss .width resd 1 ; make width local with . .number resd 1 ; make number local with . SECTION .text pushad ; save all 32-bit GP registers mov [PrintInt.number],eax mov dword [PrintInt.width],0; initialize width at 0 ; ; if (number == 0) ; width = 0 ; else ; width = log_10(number) = log_2(number) / log_2(10) ; cmp dword[PrintInt.number],0 je .L0 fld1 ; st(0) = 1.0 (load constant 1.0) fild dword [PrintInt.number] ; st(0) = number; st(1) = 1.0 fyl2x ; computes st(0) = st(1) * log_2(st(0)) fldl2t ; st(0) = log_2(10.0) ; st(1) = log_2(multiplicand) fdiv ; st(1) = st(1) / st(0) ; pop stack fisttp dword [PrintInt.width] ; store truncated integer and pop .L0: inc dword [PrintInt.width] ; add one to width ; ; insert enough spaces to eventually right justify number in a field of ; width 10 ; mov ecx,10 sub ecx,[PrintInt.width] .L1: cmp ecx,0 jle .L2 mov al,' ' call WriteChar dec ecx jmp .L1 .L2: mov eax,[PrintInt.number] call WriteDec popad ; restore all 32-bit GP registers ret