Hello, I have a few questions about Assembly. I am extremely new to it!

Question 1:
How do you write functions in assembly? Is it even possible?

Question 2:
How do you get an input to a dd variable type (do I have to do the math on four db inputs?)

Question 3:
Is it possible to make arrays in Assembly? If so how?

Thank you for any help! I am using masm32 with 16-bit link and CodeView v4.

Dani AI

Generated

Short, practical clarifications that build on the replies from and for 16‑bit MASM (masm32 + 16‑bit link + CodeView v4).

Functions/procs: MASM supports named procedures. In 16‑bit code you normally create a stack frame (save BP, set BP = SP) and reference parameters at fixed offsets from BP. Be aware of near vs far procedures: a near call keeps the caller's CS, a far call pushes both CS:IP and needs a far return. Calling conventions matter (who cleans the stack) — common conventions put 8/16/32‑bit returns in AL/AX/DX:AX respectively, so plan how your caller reads the result. For details on MASM PROC usage see the MASM reference on PROC (MASM PROC).

Putting a 32‑bit (DD) value together: a DD is just two 16‑bit words in 16‑bit code. If four input bytes must be combined into one little‑endian dword, load the low two bytes into one 16‑bit register, the high two into another, then store them as the low and high words of the DD. Example (byte source at SI, destination label dwordVar):

; build little-endian 32-bit value from four bytes
mov al, [si]
mov ah, [si+1]
mov bx, ax        ; low word
mov al, [si+2]
mov ah, [si+3]
mov cx, ax        ; high word
mov [dwordVar], bx
mov [dwordVar+2], cx

If parsing decimal text into a 32‑bit integer, implement repeated multiply‑by‑10 and add digit using 16x16 multiplies and carry propagation (ADC) between the low/high words.

Arrays: you can allocate static arrays in the data segment with DB/DW/DD and index them by element size. Example declarations:

myBytes  DB  10 DUP(?)
myWords  DW  5 DUP(?)
myDWords DD  4 DUP(?)

Indexing uses base + index*element_size (use SI/DI/BX for addressing or compute an offset into BP frame for stack arrays). Stack allocation (as noted) is fine for temporary buffers but be careful to restore SP or use a BP‑based frame when debugging in CodeView.

If targeting true 16‑bit programs long term, consider using a dedicated 16‑bit MASM/TASM toolchain rather than the masm32 defaults; debugging and calling conventions differ between 16/32‑bit environments. For calling convention background see the x86 calling conventions overview (Wikipedia).

Recommended Answers

All 2 Replies

1.

ProcName proc
  ; code here

  ret
ProcName endp

2. Don't know 16bit asm, but this should work, dwMyVar is a DWORD in the uninitialized data section

mov   dwMyVar, eax ; or mov   dwMyVar, 1 etc

3. unsure in 16 bit

Arrays work the same in 16-bit and 32-bit, you just have to allocate enough memory on the stack that you need.

; allocate space for an array of 10 bytes

sub sp, 10
mov bx, sp

; bx is the pointer to the start of the array
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.