0

A function is given:

;5X-15, X<=40
;160+X/8, 40<X<=200
;X+50, X>200 

Program code.

.486
.model flat, stdcall
option casemap: none
.stack 100h
;=========================================
include <\masm32\include\kernel32.inc>
includelib <\masm32\lib\kernel32.lib>
;=========================================
.data
x db 41
y db ?
myerr db 0
;=========================================
.code
main:

cmp x, 40
JA int2 

mov ax, 5
mul x   

sub al, 15 

jc osh      
jmp exit    

int2:
cmp x, 200
JA int3 

; 160 + x / 8
mov bl, 8
mov al, x
div al, bl ;(error here)

add al, 160

jc osh      
mov al, bl 
jmp exit    

int3:
add x, 50

jc osh      
mov al, x 
jmp exit

osh: mov myerr, 1
exit: mov al, myerr
invoke ExitProcess, al
end main

With the help of cmp I divide the code into three semantic parts. When x is compared with a constant, it jumps to the next section or calculation.

The code was written on subsidies from the textbook, but apparently I missed some detail or did not take into account some versions.

I get an error while compiling and I can't figure out what the problem is

task.asm(43) : error A2008: syntax error : ,
  • Try removing the `, bl` part. – Erik Eidt Oct 11 '22 at 18:42
  • @ErikEidt: I hope you mean removing the `al,` part. `div al` would compute AX/AL. – Peter Cordes Oct 11 '22 at 20:40
  • @PeterCordes, just trying to get the querent past the syntax error and the swearing assembler, first (getting to their actual intent would be another step). – Erik Eidt Oct 11 '22 at 20:53
  • @ErikEidt: Just closing as a duplicate would have done that; pointing someone in the wrong direction is not good even if they didn't bother to consult an instruction-set reference in the first place to realize that `div` is somewhat like `mul` which they used correctly. – Peter Cordes Oct 11 '22 at 21:06
  • @PeterCordes, I would have hoped that experiment would have set them in the direction toward the proper way to use `div` taking only one operand. However, as we're at it let's also point out a full 16-bit value is needed in `ax` in order to use `div bl`. – Erik Eidt Oct 11 '22 at 21:58
  • @ErikEidt: I was thinking it still was after `mul x` (and didn't mention it since the linked duplicate covers that as well, IIRC). But they're actually putting some other value into AL before the `div`. Still, their `mul` result happens to be narrow enough that AH=0, so `mov al, x` does zero-extend `x` into AX. – Peter Cordes Oct 11 '22 at 22:06

0 Answers0