https://www.csee.umbc.edu/portal/help/nasm/sample.shtml

http://derekmolloy.ie/writing-a-linux-kernel-module-part-2-a-character-device/

Skip to content
# Category: Programming

## Linux asm examples, links

## 8086 disassembler using 64 bit assembly language

## Good article on data alignment

## Ackermann function in Clojure, verion 1

## Program to find GCD of two polynomials

## PowerBuilder, disable system menu`s close button

## No more COM in PowerBuilder 12

## PowerBuilder, different DD list values for each row, another way

## PowerBuilder, different DD list values for each row

#### Step 1 – declare instance variables

#### Step 2 – extend the pbm_dropdown event

#### Step 3 – extend the pbm_ncpaint event

#### Step 4 – write the of_Filter (boolean ab_switch) subroutine

## Bowerbuilder datawindow autosize problem

Notes, hacks, hints/software, hardware, life

8086 disassembly application. Project done during computer architecture course.

Project is done using nasm(yasm) 64 bit assembly and some c functions to handle input/output.

I have chosen such technologies because I was curious about few topics:

- Learning about asm 64 bit programming
- Compiling assembly executable for windows 64 platform. During the comp architecture course we were doing assembly programming for a ms dos using dosbox. I was interested in making some executable code on a windows 64 platform.
- Linking assembly code to some higher lever programming language library. During the comp architecture course we were using dos api (int) to handle input, output and some other manipulations. For modern platform you could use windows api function calls or libraries from higher level programming languages. I have chosen to use c and use some basic c input output functions.
- Understanding assembly procedure calls on 64 platform and differences between win 64 calls and unix/posix 64 calls.
- Disassembling some simple c applications and exploriing how assembly code is constructed using c compile. To understand how some c function calls are made I have used some super simple c programs that I decompiled using gdb.

This project can be found in github.

Good article on data structure alignment in C

https://wr.informatik.uni-hamburg.de/_media/teaching/wintersemester_2013_2014/epc-14-haase-svenhendrik-alignmentinc-paper.pdf

(defn ack [m n] (if (= m 0) (inc n) (if (= n 0) (ack (dec m) 1) (ack (dec m) (ack m (dec n))))))

The objective is to write a program that finds greatest common divisor of two polynomials g(x) and h(x).

The task does not define what form we get those two polynomials, so let’s say we will get them in a form of a String, something like that:

Let’s start splitting our problem into chunks and gather some information about the steps we would need to implement.

First, what is the *greatest common divisor*? In math, GCD of two or more integers,* which are not all zero*, is the *largest positive integer that divides each of the integers* (1).

How do we find it? One way is to use the Euclidean algorithm. The intuition behind this algorithm is such: we have A and B numbers. We divide A by B and get C. If C is 0 – then B is our GCD. If it is not 0, then we set A to B and B to the reminder and continue operation until we get 0.

Let’s say we have 12 and 9. 12 mod 9 is 3. 9 mod 3 is 0. So our GCD is 3.

Ok, now we know about GCD and Euclidian algorithm. Next topic – Polynomials.

Polynomial is an expression consisting of variables (x,y,z etc) and coefficients, that involves only operations of addition, subtraction, and non-negative exponents of variables.

Example of a polynomial with single indeterminate ( variable ) x is

An example in three variables is

Our objective states to find GCD of g(x) and h(x) polynomials, so we assume objective is to find GCD of single variable polynomials.

Also, for the sake of simplicity, we could say that polynomial consists of a list of monomials with the same variable. Each monomial is made of an optional coefficient, optional variable with optional non-negative integer exponent.

So in we have list of monomials , and .

Now we have defined GCD and polynomials. But can we apply the Euclidean algorithm to find GCD for Polynomials? And the short answer is yes.

We will supose that *deg(g(x)) <= deg(h(x))*.

Then we find two polynomials q(x) and r(x) that satisfy:

Where q is quotient and r is reminder.

Then we set and .

And we repeat polynomial long division to get now polynomials and so on until we reach point when we get .

Lets conclude what we knwo at this point: we know what is GCD, we know abut Euclidean algorithm to find GCD, we know about polynomials and monomials and we know that we can apply Euclidean algorithm to find GCD for polynomials.

There are some things to find out though. When applying the Euclidean algorithm to polynomials we use Polynomial long division for dividing a polynomial by a polynomial of the same or lower degree.

We will have to implement this either to get our quotient and remainder of the polynomial division.

- divide the first term of the dividend by the highest term of the divisor
- multiply the divisor by the result just obtained
- subtract the product just obtained from the appropriate terms of original dividend
- repeat the previouss three steps except this time use the two terms that have just been written as the dividend.

Example:

Divide

**Step 1.** Make sure polynomial is written in descending order. If any term missing, use a zero to fill in the missing term. In this case we should get:

**Step 2.** Divide the term with the highest power inside the division symbol by the term with the highest power outside the division symbol. It his case, we have divided by which is .

**Step 3.** Multiply the answer obtained in the previous step by the polynomial in front of the division symbol. In this case we need to multiply 3x and x^2 – 1.

**Step 4**: Subtract and bring down the next term.

**Step 5**: Divide the term with the highest power inside the division symbol by the term with the highest power outside the division symbol. In this case, we have –2x^{2} divided by x^{2} which is –2.

**Step 6**: Multiply (or distribute) the answer obtained in the previous step by the polynomial in front of the division symbol. In this case, we need to multiply –2 and x^{2} – 1.

**Step 7**: Subtract and notice there are no more terms to bring down.

The polynomial above the bar is the quotient *q*(*x*), and the number left over (3x+4) is the remainder *r*(*x*).

*If A* = *BQ* + *R then*

**Step 8**: Write the final answer. The term remaining after the last subtract step is the remainder and must be written as a fraction in the final answer.

i.e.

(Example is taken from here )

Looking at those steps we can see that we will need to implement those primitive steps in our application:

- Polynomial sort by exponents.
- Polynomial missing term expansion.
- Monomial division.
- Monomial multiplication.
- Monomial subtraction.

So now: we know what is GCD, we know about Euclidean algorithm to find GCD, we know about polynomials and monomials and we know that we can apply Euclidean algorithm to find GCD for polynomials and then we know how to perform long division on polynomials.

At this point we have enough information and can start writing some code.

ulong ll_parent_hwnd

ulong ll_sys_menu_hwnd

ulong ll_sys_menu_close_flags

ulong ll_ret

n_cst_numerical u_num

ll_parent_hwnd = Handle(this.parentwindow())

ll_sys_menu_hwnd = GetSystemMenu(ll_parent_hwnd, FALSE)

ll_sys_menu_close_flags = GetMenuState(ll_sys_menu_hwnd, SC_CLOSE, MF_BYCOMMAND )

ll_ret = u_num.of_bitwiseand(ll_sys_menu_close_flags , MF_DISABLED)

ib_close_prev_enabled = (ll_ret = 0)

If ib_close_prev_enabled Then

EnableMenuItem (ll_sys_menu_hwnd, SC_CLOSE, MF_BYCOMMAND + MF_DISABLED + MF_GRAYED)

End If

And to enable it later:

If ib_close_prev_enabled Then

EnableMenuItem (GetSystemMenu(handle(parentwindow()), FALSE), SC_CLOSE, MF_BYCOMMAND + MF_ENABLED)

End If

Just for a reminder and possible workaround to wint a .NET dll:

https://archive.sap.com/discussions/thread/3847610

The Ol’ Hidden Items in the Dddw Problem Part II

Make a second copy of the Color column and have this always contain all the rows in its dddw. This second column is never filtered.

When the row is not the current row, display the column with the unfiltered dddw and hide the filter column. If the row is the current row, show the column with the filtered dddw, and hide the column with the dddw with all the possible rows. To do this, add the following expression to the visibility attribute of the column with the dddw which gets filtered:

IF (CurrentRow() = GetRow(), 1, 0)

The column with the dddw which always contains all the values will have the following expression in its visibility attribute:

IF (CurrentRow() = GetRow(), 0, 1)

Source http://www.pbdr.com/pbtips/dw/fltrdddw.htm

boolean ib_dropdowndropped = False boolean ib_dropdownredrawn = True

ib_dropdowndropped = True ib_dropdownredrawn = False of_Filter(True) ib_dropdownredrawn = True

If (ib_dropdowndropped And ib_dropdownredrawn) Then ib_dropdowndropped = False ib_dropdownredrawn = False of_Filter(False) ib_dropdownredrawn = True End If

datawindowchild ldwc long ll_getitemnumber string ls_setfilter = "" If (ab_switch) Then ll_getitemnumber = GetItemNumber(GetRow(), "order_status_id") If (ll_getitemnumber = 1) Then // cancelled -> cancelled ls_setfilter = "(order_status_id = 1)" ElseIf (ll_getitemnumber = 2) Then // confirmed -> confirmed ls_setfilter = "(order_status_id = 2)" ElseIf (ll_getitemnumber = 3) Then // new -> cancelled, new, pending ls_setfilter = "(order_status_id = 1) or (order_status_id = 3) or (order_status_id = 4)" ElseIf (ll_getitemnumber = 4) Then // pending -> cancelled, confirmed, pending ls_setfilter = "(order_status_id = 1) or (order_status_id = 2) or (order_status_id = 4)" End If End If GetChild("order_status_id", ldwc) ldwc.SetFilter(ls_setfilter) ldwc.Filter()

You have a datawindow. Datawindow has an Autosize Height set to Details band. You insert a row, set a long string value to some field expecting that field to be auto-sized. And it is, but you don’t see a text as Details band does not auto-size. What to do? Whan way to fix this is to call Sort() somewhere after you set v the value fro the datawindow to refresh and auto-size to take effect. But that does not work all times ( for example … you dont want to sort data now). Another way is to set:

dw.Modify ( ‘DataWindow.Header.Height.AutoSize=yes’)

This will also make datawindow to resize all the bands and auto-size will take effect then.